How to scroll layout which have 3 list view

后端 未结 5 773
情歌与酒
情歌与酒 2021-02-08 02:13

I have one layout. This layout contain 3 list view with the height of wrap_content data in the Listview are not fix. When Listview have a liitel huge data at that time the data

5条回答
  •  鱼传尺愫
    2021-02-08 02:24

    Use this method and your listview become scrollable inside scrollview:-

    ListView lstNewsOffer.setAdapter(new ViewOfferAdapter(
                            ViewNewsDetail.this, viewOfferList));
                    getListViewSize(lstNewsOffer);
    
     void getListViewSize(ListView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();
    if (myListAdapter == null) {
        // do nothing return null
        return;
    }
    // set listAdapter in loop for getting final size
    int totalHeight = 0;
    for (int size = 0; size < myListAdapter.getCount(); size++) {
        View listItem = myListAdapter.getView(size, null, myListView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    // setting listview item in adapter
    ViewGroup.LayoutParams params = myListView.getLayoutParams();
    params.height = totalHeight
            + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
    myListView.setLayoutParams(params);
    // print height of adapter on log
    Log.i("height of listItem:", String.valueOf(totalHeight));
    

    }

提交回复
热议问题