得到的布局的高度和宽度编程 [英] Get height and width of a layout programatically
问题描述
我已经设计了一个布局,其中的LinearLayout
有2个孩子的LinearLayout
和的FrameLayout
并在每个孩子,我把不同的意见。
I have designed an layout in which LinearLayout
has 2 children LinearLayout
and FrameLayout
and in each child I put different views.
我只是想衡量的FrameLayout
的高度和宽度,这样我可以为我的目的。
I just wanted to measure height and width of FrameLayout
so that I could serve my purpose.
在程序我用
int height,width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getHeight();
width=fr.getWidth();
返回值 0
为
即使我试着用以下的code INT高度,宽度;
Even I tried with following code int height,width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getMeasuredHeight();
width=fr.getMeasuredWidth();
返回相同的值 0
最后我试着用以下的code, INT高度,宽度;
and finally I tried with following code, int height,width;
FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getgetLayoutParams().height();
width=fr.getLayoutParams().width;
返回我 -2
和 1
我想要的解决方案,以获得任何布局的高度和宽度编程??
I want the solution to get height and width of any layout programatically??
推荐答案
我觉得你得到高度和宽度的OnCreate()方法,这就是为什么你因为那个时候你的观点仍然没有建立让始终为0值。
I think you are getting Height and Width in OnCreate() method that's why you getting always 0 values because at that time your view still not created.
设法得到高度和宽度上的一些按钮,点击要不然......
Try to get height and width on some button click or else..
这篇关于得到的布局的高度和宽度编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!