标签:
动态设置ListView的高度
public void setListViewHeightBasedOnChildren(ListView mListView) { ListAdapter listAdapter = mListView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, mListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = mListView.getLayoutParams(); params.height = totalHeight + (mListView.getDividerHeight() * (listAdapter.getCount() - 1)); ((MarginLayoutParams) params).setMargins(10, 10, 10, 10); mListView.setLayoutParams(params); }
在ScrollView中嵌套ListView时,需要根据内容来设置listView的高度
标签:
原文地址:http://blog.csdn.net/luoyinhan/article/details/42613323