android listview 高度自适应

发布时间:2019-02-22 20:26:01
setListViewHeightBasedOnChildren(ListView listView) {
     ListAdapter listAdapter = listView.getAdapter();
     (listAdapter == ) {
      ;
     }
     totalHeight = ;
     (i = ; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, , listView);
      listItem.measure(, ); totalHeight += listItem.getMeasuredHeight(); }
     ViewGroup.LayoutParams params = listView.getLayoutParams();
     params.= totalHeight
       + (listView.getDividerHeight() * (listAdapter.getCount() - ));
     listView.setLayoutParams(params);
}


将相应的listview传入

setListViewHeightBasedOnChildren(filelv);



Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米
Card image cap
华为