ViewGroup.LayoutParams params = expandableListView.getLayoutParams(); int height = totalHeight + expandableListView.getDividerHeight() * (adapter.getGroupCount() - 1);
ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1)); listView.setLayoutParams(params);
private void setListViewHeight(ExpandableListView listView) { ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter(); int totalHeight = 0; for (int i = 0; i < listAdapter.getGroupCount(); i++) { View groupView = listAdapter.getGroupView(i, true, null, listView); groupView.measure(0, View.MeasureSpec.UNSPECIFIED); totalHeight += groupView.getMeasuredHeight(); if (listView.isGroupExpanded(i)){ for(int j = 0; j < listAdapter.getChildrenCount(i); j++){ View listItem = listAdapter.getChildView(i, j, false, null, listView); listItem.measure(0, View.MeasureSpec.UNSPECIFIED); totalHeight += listItem.getMeasuredHeight(); } } } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
ViewGroup.LayoutParams params = listView.getLayoutParams(); int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
ViewGroup.LayoutParams params = listView.getLayoutParams(); int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
ViewGroup.LayoutParams params = listView.getLayoutParams(); int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
private void setExpandableListViewHeightBasedOnChildren(ExpandableListView expandableListView, Integer expandedGroupPosition) { ExpandableListAdapter expandableListAdapter = expandableListView.getExpandableListAdapter(); if (expandableListAdapter == null) { return; } int totalHeight = 0; int totalDividerHeight = 0; for (int i = 0; i < expandableListAdapter.getGroupCount(); i++) { View groupItem = expandableListAdapter.getGroupView(i, expandedGroupPosition != null, null, expandableListView); totalHeight += Utils.convertDpToPixel(92.42f, this); if(expandedGroupPosition != null && expandedGroupPosition.equals(i)) { for(int j=0;j<expandableListAdapter.getChildrenCount(i);j++) { View childItem = expandableListAdapter.getChildView(i, j, j+1==expandableListAdapter.getChildrenCount(i), null, expandableListView); totalHeight += Utils.convertDpToPixel(92.42f, this); } totalDividerHeight += expandableListView.getDividerHeight() * (expandableListAdapter.getChildrenCount(i)-1); } } totalDividerHeight += expandableListView.getDividerHeight() * (expandableListAdapter.getGroupCount()-1); ViewGroup.LayoutParams params = expandableListView.getLayoutParams(); params.height = totalHeight + totalDividerHeight; expandableListView.setLayoutParams(params); expandableListView.requestLayout(); }