我设计了一个布局,其中LinearLayout
有2个子元素LinearLayout
和FrameLayout
,并在每个子元素中放置不同的视图。
我只想测量FrameLayout
的高度和宽度,以便达到我的目的。
在程序中,我正在使用
int height,width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getHeight();
width=fr.getWidth();
返回值对于两者都是0
尝试以下代码后,甚至包括: int height, width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getMeasuredHeight();
width=fr.getMeasuredWidth();
返回相同的值0
最后我尝试了以下代码, int height,width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getgetLayoutParams().height();
width=fr.getLayoutParams().width;
返回给我的是 -2
和 -1
我想要通过编程获取任何布局的高度和宽度的解决方案?