获取Android控件的真实宽高,亲测有效
来源:互联网 发布:手机底部导航栏源码 编辑:程序博客网 时间:2024/06/05 09:49
//方法1int 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();
---------------------------------------------------------------------
//方法2ViewTreeObserver vto = imageView.getViewTreeObserver();vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { vto.removeOnPreDrawListener(this); int height = imageView.getMeasuredHeight(); int width = imageView.getMeasuredWidth(); return true; }});---------------------------------------------------------------------//方法3ViewTreeObserver vto = imageView.getViewTreeObserver();vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this); imageView.getHeight(); imageView.getWidth(); }});
阅读全文
0 0
- 获取Android控件的真实宽高,亲测有效
- 获得Android控件的真实宽高:
- android开发:获取键盘的高度(实测真实有效)
- IOS获取屏幕的真实宽高
- 获取图片的真实宽高
- Android中获取控件的宽高
- Android开发 获取控件的宽高
- Android获取UI控件的宽高
- 获取android控件的宽高
- android获取控件宽高
- android获取控件宽高
- android 平板获取真实宽高(包括状态栏)
- Android 获取Android控件的宽和高
- Android获取Android控件的宽和高
- 获取控件的宽高
- 控件的宽高获取
- 获取控件的宽高
- 获取控件的宽高
- 关于 SELinux 设置遇到的相关问题
- [莫比乌斯反演] BZOJ4816: [Sdoi2017]数字表格
- 基于dfa的kmp算法思想
- 微信公众平台授权
- Redis之——Spring基于注解整合Redis
- 获取Android控件的真实宽高,亲测有效
- java通过poi读取excel中的日期类型数据或自定义类型日期
- 【LeetCode】596、Classes More Than 5 Students
- java list排序
- java Graphics初探
- seh
- Python 自定义异常
- 使用prototype自定义数组方法
- HTML标签