getHeight returns 0 for all Android UI objects
2024-08-25 17:12:43
It's 0 because in both onCreate and onStart, the view hasn't actually been drawn yet. You can get around this by listening for when the view is actually drawn:
final TextView tv =(TextView)findViewById(R.id.venueLabel);
final ViewTreeObserver observer = tv.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
@Override
publicvoid onGlobalLayout()
{
tv.getHeight();
observer.removeGlobalOnLayoutListener(this);
}
});
The call to remove the listener is there to prevent repeated invocations of your custom handler on layout changes... if you want to get those, you can omit it.
http://stackoverflow.com/questions/8170915/getheight-returns-0-for-all-android-ui-objects
最新文章
- 轻量级前端MVVM框架avalon - 模型转换
- 关于本月第一天,本月最后一天的SQL代码
- C++ 中数串互转、进制转换的类
- FZU 2191 完美的数字
- 严重: The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it.
- ECNU1104-BFS
- asp.net中应用JQuery.pagination分页
- Java代理模式——静态代理模式
- SQLServer,仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表xx中的标识列指定显式值
- [转载]LVS快速搭建教程
- Kafka 使用Java实现数据的生产和消费demo
- LeetCode &; Q88-Merge Sorted Array-Easy
- 【转】Mac 删除文件夹里所有的.svn文件
- loadrunner脚本函数讲解
- DAY15 模块
- Android开发之adb,$Sqlite篇
- java使用freemarker模板导出word(带有合并单元格)文档
- ES6箭头函数this指向
- C语言复习---迭代法,牛顿迭代法,二分法求根
- .NetCore下使用Prometheus实现系统监控和警报 (一)介绍【译】