android - ListView動態(tài)測量高度,為什么數(shù)據(jù)刷新了重新測量,listview底部會出現(xiàn)大量空白
問題描述
ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) {return; } int totalHeight = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { //listAdapter.getCount()返回數(shù)據(jù)項的數(shù)目View listItem = listAdapter.getView(i, null, listView);listItem.measure(0, 0); //計算子項View 的寬高totalHeight += listItem.getMeasuredHeight(); //統(tǒng)計所有子項的總高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); // listView.getpiderHeight()獲取子項間分隔符占用的高度 int piderHeight = (listView.getpiderHeight() * (listAdapter.getCount() - 1)); // params.height最后得到整個ListView完整顯示需要的高度:item總和 + 分割線總和高度 params.height = totalHeight + piderHeight; listView.setLayoutParams(params);
問題解答
回答1:不太了解樓主的需求啊,listview warp一下不就行了嗎