ScrollView 下 ListView显示不全的问题
有的时候,ScrollView下ListView列表显示不完整,可以用下面的code解决。
1
2 {
3 ListAdapter listAdapter = listView.getAdapter();
4 if (listAdapter == null)
5 {
6 return;
7 }
8 int totalHeight = 0;
9 for (int i = 0, len = listAdapter.getCount(); i < len; i++)
10 {
11 View listItem = listAdapter.getView(i, null, listView);
12 listItem.measure(0, 0);
13 totalHeight += listItem.getMeasuredHeight();
14 }
15 ViewGroup.LayoutParams params = listView.getLayoutParams();
16 params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) + listView.getPaddingTop() + listView.getPaddingBottom();
17 listView.setLayoutParams(params);
18 }
1