How to customized the ListView height in android?

前端 未结 4 1399
说谎
说谎 2021-01-24 08:41

I am a beginner to android. I want to display a customized list view which contains a number. I customized my ListView size(android:layout_height=\"50dp\"

4条回答
  •  礼貌的吻别
    2021-01-24 09:23

    This should help you out..

    ListAdapter listadp = lv_ancillaryservice.getAdapter();
       if (listadp != null) {
           int totalHeight = 0;
           for (int i = 0; i < listadp.getCount(); i++) {
               View listItem = listadp.getView(i, null, lv_ancillaryservice);
               listItem.measure(0, 0);
               totalHeight += listItem.getMeasuredHeight();
           }
           ViewGroup.LayoutParams params = lv_ancillaryservice.getLayoutParams();
           params.height = totalHeight + (lv_ancillaryservice.getDividerHeight() * (listadp.getCount() - 1));
           lv_ancillaryservice.setLayoutParams(params);
           lv_ancillaryservice.requestLayout();
    

提交回复
热议问题