我想滚动一个布局,该布局包含一开始扩展的ExpandableListView。
我在此链接中尝试了一个功能:https://thedeveloperworldisyours.com/android/expandable-listview-inside-scrollview/#comment-102209 它运行正常,但是当我单击“组”时,而不是在布局开始时展开时。我正在做一些测试,物品的高度大于实际高度。
protected void onResume() {
super.onResume();
adapter = new ExpandableDatosPersonalesAdapter(this, expandableListTitle);
listView.setAdapter(adapter);
// setOnGroupClickListener listener for group heading click
listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
setListViewHeight(parent, groupPosition);
return false;
}
});
for(int i=0;i<expandableListTitle.size();i++) {
listView.expandGroup(i);
}
setListViewHeight(listView, 4);
}
private void setListViewHeight(ExpandableListView listView,
int group) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
//Coge el ancho exacto del movil
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();
Timber.e("Altura2: "+totalHeight +" Grupo: "+i);
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();
Timber.e("Altura2: "+totalHeight+" Grupo: "+i+"Hijo: "+j);
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
int height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
if (height < 10)
height = 200;
Timber.e("Altura2: "+height);
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();
}
我想比方法捕获项目的实际高度。谢谢!