2019独角兽企业重金招聘Python工程师标准>>>
public static void setListViewHeight(ListView listView) {ListAdapter listAdapter = listView.getAdapter();int totalHeight = 0;for (int i = 0; i < listAdapter.getCount(); i++) {View listItem = listAdapter.getView(i, null, listView);listItem.measure(1, 1);totalHeight += listItem.getMeasuredHeight();}ViewGroup.LayoutParams par = listView.getLayoutParams();par.height = totalHeight+ (listView.getDividerHeight() * (listAdapter.getCount() - 1))+ listView.getPaddingTop() + listView.getPaddingBottom();listView.setLayoutParams(par); }