常用的获取宽高方法
来源:互联网 发布:servo guide软件下载 编辑:程序博客网 时间:2024/05/20 10:51
1.获取屏幕宽高(类似华为手机虚拟按键如果显示,得出的高度不包括虚拟按键)
WindowManager wm = context.getWindowManager();int width = wm.getDefaultDisplay().getWidth();int height = wm.getDefaultDisplay().getHeight();2.获取控件宽高
onCreate方法执行完之后,控件才能被测量。如果要在onCreate方法里获取控件宽高,需要我们手动测量(或者使用ViewTreeObersver),wrap/match并不能测量出尺寸
int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);imageView.measure(w, h);int height = imageView.getMeasuredHeight();int width = imageView.getMeasuredWidth();
3.获取状态栏高度
public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimensionPixelSize(resourceId); } return result;}
0 0
- 常用的获取宽高方法
- 常用的计算宽高的方法
- 获取.h264视频宽高的方法
- 获取字符串显示宽高的方法
- android,获取屏幕宽高的方法
- JavaSsript获取各种宽高的方法
- jQuery获取各种宽高的方法
- Android 获取view的宽高方法
- js获取图片宽高的方法
- 自定义View常用的获取宽高信息
- 安卓 onCreate 方法获取 view 宽高的方法
- android获取view宽高的几种方法,解决获取高宽为0问题
- 获取控件的宽高的两种方法
- 获取View的宽高的三种方法
- Android--获取View的宽高的几种方法
- Android获取屏幕的宽高的方法
- android获取屏幕宽高的两种方法
- Android获取屏幕宽高的两种方法
- oracle数据导出提示EAP-00091解决办法
- slave_exec_mode对slave影响
- NSArray 快速求总和 最大值 ,最小值 平均值
- 开始csdn
- director.js 传递多个参数
- 常用的获取宽高方法
- 移动应用界面设计的尺寸设置及规范
- GIT删除存在本地,但在服务端不存在的分支的命令
- 五十道编程小题目 --- 02 找素数(质数)java
- scala学习
- CSU 1322 ZY‘s new company(线段树维护bfs序)
- Mysql Join语法解析与性能分析
- 浅谈 RxAndroid + Retrofit + Databinding
- Xamarin Android Circle ImageView 圆形图片实现