【发布时间】:2016-01-06 16:42:38
【问题描述】:
我嵌套了LinearLayouts,其父高度为90,但子视图可能根据其中设置的文本具有不同的高度,并且可能会溢出其父视图。我想将父动画设置为子的最终高度,但是子 getHeight() 和父 getMeasuredHeight() 的两种方法,返回 90 不400。
parent.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
targetHeight = parent.getMeasuredHeight();
//returns 90
还有
View child=((ViewGroup) parent).getChildAt(0);
int targetHeight=child.getHeight();
//returns 90
【问题讨论】: