我设计了一个布局,其中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
我想要的解决方案,使编程任何布局的高度和宽度?
看到这个问题 http://stackoverflow.com/questions/3779173/determining-the-size-of-an-android-view-at-runtime – VinhNT