listAdapter = new ListStringAdapter(getActivity(), strLists);
listView.setAdapter(listAdapter);
//计算listView的高度
int totalHeight = 0;
for(int i = 0; i < listAdapter.getCount(); i++){
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
//固定listView的高度
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listAdapter.notifyDataSetChanged();
固定ListView的高度
最新推荐文章于 2021-05-27 04:11:47 发布