安卓自动匹配listview的高度
/***@param自动匹配listview的高度*/publicvoidsetListviewHeight(ListViewlistView){ListAdapterlistAdapter=listView.getAdapter();if(listAdapter==null){return;}inttotalHeight=0;for(inti=0;i<listAdapter.getCount();i++){ViewlistitemView=listAdapter.getView(i,null,listView);listitemView.measure(0,0);totalHeight+=listitemView.getMeasuredHeight();}ViewGroup.LayoutParamsparams=listView.getLayoutParams();params.height=totalHeight+(listView.getDividerHeight()*(listAdapter.getCount()-1));((MarginLayoutParams)params).setMargins(0,0,0,0);listView.setLayoutParams(params);}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。