永发信息网

我真的没有办法了 expandablelistview 为什么子视图显示不出来

答案:1  悬赏:60  手机版
解决时间 2021-11-27 09:54
  • 提问者网友:伴风望海
  • 2021-11-27 00:49
我真的没有办法了 expandablelistview 为什么子视图显示不出来
最佳答案
  • 五星知识达人网友:妄饮晩冬酒
  • 2021-11-27 02:27
ScrollView嵌套ListView或ExpandableListView产问题说懒- -

直接说解决办吧:

  其实需要计算adapter所item高度再设置给listiew

代码封装listview.setAdapter()调用行

public static class Utility {
public static void setListViewHeightBasedOnChildren(ExpandableListView listView) {
//获取ListView应Adapter
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}

int totalHeight = 0;
for (int i = 0, len = listAdapter.getCount(); i < len; i++) { //listAdapter.getCount()返数据项数目
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0); //计算项View 宽高
totalHeight += listItem.getMeasuredHeight(); //统计所项总高度
}

ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
//listView.getDividerHeight()获取项间隔符占用高度
//params.height整ListView完整显示需要高度
listView.setLayoutParams(params);
}
}

测试完全行
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯