android expandablelist 自动滚动,Android – 包含ExpandableListView的NestedScrollView在展开时不会滚动...

使用此方法,这将在运行时计算ExpendableListSize。

private void setListViewHeight(ExpandableListView listView, int group) { ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter(); int totalHeight = 0; int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY); for (int i = 0; i < listAdapter.getGroupCount(); i++) { View groupItem = listAdapter.getGroupView(i, false, null, listView); groupItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += groupItem.getMeasuredHeight(); if (((listView.isGroupExpanded(i)) && (i != group)) || ((!listView.isGroupExpanded(i)) && (i == group))) { for (int j = 0; j < listAdapter.getChildrenCount(i); j++) { View listItem = listAdapter.getChildView(i, j, false, null, listView); listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += listItem.getMeasuredHeight(); } } } ViewGroup.LayoutParams params = listView.getLayoutParams(); int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1)); if (height < 10) height = 200; params.height = height; listView.setLayoutParams(params); listView.requestLayout(); }

在下面的setOnGroupClickListener.like中调用此方法

mExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { setListViewHeight(parent, groupPosition); return false; } });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值