ListView dynamically measures height. Why is there a large amount of blank space at the bottom of listview when the data is refreshed and re-measured

  android, question
ListAdapter listAdapter = listView.getAdapter();
 if (listAdapter == null) {
 
 return;
 bracket
 
 int totalHeight = 0;
 for (int i = 0, len = listAdapter.getCount();   i < len;  Getcount () returns the number of data items
 View listItem = listAdapter.getView(i, null, listView);
 listItem.measure(0, 0);  //Calculate the width and height of sub-item View
 TotalHeight plus = listItem.getMeasuredHeight ();  //Count the total height of all sub-items
 bracket
 ViewGroup.LayoutParams params = listView.getLayoutParams();
 // listView.getDividerHeight () gets the height occupied by separators between children
 int dividerHeight = (listView.getDividerHeight() * (listAdapter.getCount() - 1));
 // params.height finally obtains the height required for the full display of the entire ListView: sum of item plus sum of dividing lines
 Params.height = totalHeight plus dividerHeight;
 
 listView.setLayoutParams(params);

图片描述

I don’t know much about the needs of the building owner, isn’t listview warp enough?