标签:android c class blog code java
上午在做一个QuickAction里嵌套一个ListView,在Demo运行没事,结果引入到我的项目里,发现我先让它在Button上面,结果是无视那个Button的高度,这很明显,就是那个Button的高度计算不正确。
看了下别人的建议,大概分为三类:
mRootView.measure( 0 , 0 ); |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
ViewTreeObserver vto =view.getViewTreeObserver(); vto.addOnPreDrawListener( new
ViewTreeObserver.OnPreDrawListener() { @Override public
boolean onPreDraw() { int
height =view.getMeasuredHeight(); int
width =view.getMeasuredWidth(); } }); |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
//增加整体布局监听 ViewTreeObserver vto = view.getViewTreeObserver(); vto.addOnGlobalLayoutListener( new OnGlobalLayoutListener(){ @Override public voidonGlobalLayout() { view.getViewTreeObserver().removeGlobalOnLayoutListener( this ); int height =view.getMeasuredHeight(); int width =view.getMeasuredWidth(); } }); |
Android 计算view 的高度,布布扣,bubuko.com
标签:android c class blog code java
原文地址:http://www.cnblogs.com/Cyning/p/3767665.html