The morning in a quickaction nested a ListView, in the demo run Nothing, the results introduced into my project, I found that I first let it on the button, the result is to ignore the height of the button, it is obvious that the button's height calculation is incorrect.
Look at other people's suggestions, probably divided into three categories:
Parameter settings:
?
Callback prior to draw:?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
ViewTreeObserver vto =view.getViewTreeObserver(); vto.addOnPreDrawListener(newViewTreeObserver.OnPreDrawListener() { @Override publicboolean onPreDraw() { intheight =view.getMeasuredHeight(); intwidth =view.getMeasuredWidth(); } }); |
All listening:
?
| 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(newOnGlobalLayoutListener(){ @Override publicvoidonGlobalLayout() { view.getViewTreeObserver().removeGlobalOnLayoutListener(this); intheight =view.getMeasuredHeight(); intwidth =view.getMeasuredWidth(); } }); |