Android 在OnCreate()中获取控件高度与宽度
来源:互联网 发布:python交换两个值 编辑:程序博客网 时间:2024/04/30 06:15
http://blog.sina.com.cn/s/blog_821e2bb101010yin.html
试过在OnCreate()中获取控件高度与宽度的童鞋都知道,getWidth()与getHeight()方法返回是0,具体原因看一下Activity的生命周期 就会明白。
方法一:
int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); ssidtext.measure(w, h); int width =ssidtext.getMeasuredWidth(); int height =ssidtext.getMeasuredHeight();
方法二:
ViewTreeObserver vto = ssidtext.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { int height = ssidtext.getMeasuredHeight(); int width = ssidtext.getMeasuredWidth(); return true; } });
具体用哪一种可以根据需求自己选择。
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- Android 在OnCreate()中获取控件高度与宽度
- android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- Android在OnCreate中获取控件的宽度和高度
- 找出n个数组成的最长单调递增子序列( 动态规划O(nlogn) )
- KMP算法
- Drupal Views的帮助文档都有哪些?
- KMP字符串匹配
- HTTP学习总结-------1
- Android 在OnCreate()中获取控件高度与宽度
- ios 发送http协议请求消息
- Jquery动态增加行和删除行
- iOS应用的真机调试
- 11级_Java_曹建波6.07 MySQL语言结构
- Python编写FTP下载程序
- activity传参数与跳转
- EZ-USB 68013学习笔记(二)——USB协议之传输的基本单元--包
- 投影仪的使用