【发布时间】:2014-02-21 06:13:20
【问题描述】:
我设计了一个布局,其中LinearLayout 有两个孩子LinearLayout 和FrameLayout,我在每个孩子中放置不同的视图。
我只是想测量FrameLayout 的高度和宽度,以便达到我的目的。
在我正在使用的程序中
int height,width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getHeight();
width=fr.getWidth();
返回值为0
即使我尝试使用以下代码 int 高度,宽度;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getMeasuredHeight();
width=fr.getMeasuredWidth();
返回相同的值0
最后我尝试了以下代码, int 高度,宽度;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getgetLayoutParams().height();
width=fr.getLayoutParams().width;
回复我-2 和-1
我希望解决方案以编程方式获取任何布局的高度和宽度?
【问题讨论】:
-
一篇很好的文章,有助于了解何时以及如何设置 android 视图尺寸 cheesecakelabs.com/blog/…