固定ListView的高度

	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的高度)