如何确定Android View的大小(以像素为单位)?

时间:2012-03-29 23:25:37

标签: android

是否有直接的编程方式来获取fill_parent View的像素高度和宽度?例如,选项卡中网格布局中的视图。或者我是否必须获取窗口大小并减去其周围视图的静态大小?

2 个答案:

答案 0 :(得分:14)

您可以通过致电myView.getParent()并使用getWidth()getHeight()获取您需要的像素来获取观看次要内容。 该文档为此主题提供了更多信息 http://developer.android.com/reference/android/view/View.html

答案 1 :(得分:0)

onMeasure()方法,不确定是否能满足您的需求。 http://developer.android.com/guide/topics/ui/custom-components.html