我在BaseExpandableListAdapter
。{/ p>之一中使用了ListAdapters
要求是获取父ListItem
的高度。
我尝试在getGroupView()
中使用以下代码:
listItem.measure(0, 0);
totalHeight = listItem.getMeasuredHeight();
但是totalHeight返回0。
那么,&我可以在哪里计算高度?
谢谢
答案 0 :(得分:1)
您想使用onPreDrawListener。
高度为0,因为你要求它的高度,而它尚未铺设,所以你必须等待布局。
这大致是您的代码应该是什么样子
convertView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
listItem.measure(0, 0);
totalHeight = listItem.getMeasuredHeight();
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});