1 回答
![?](http://img1.sycdn.imooc.com/54584f8f00019fc002200220-100-100.jpg)
胡子哥哥
TA贡献1825条经验 获得超6个赞
/**
02
03 * 设置Listview的高度
04
05 */
06
07 public voidsetListViewHeight(ListView listView) {
08
09 ListAdapter listAdapter = listView.getAdapter();
10
11 if(listAdapter == null) {
12
13 return;
14
15 }
16
17 inttotalHeight = 0;
18
19 for (inti = 0; i < listAdapter.getCount(); i++) {
20
21 View listItem = listAdapter.getView(i, null, listView);
22
23 listItem.measure(0, 0);
24
25 totalHeight += listItem.getMeasuredHeight();
26
27 }
28
29 ViewGroup.LayoutParams params = listView.getLayoutParams();
30
31 params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
32
33 listView.setLayoutParams(params);
34
35 }
添加回答
举报
0/150
提交
取消