Android, How to add ScrollView into screen which has some list items?

后端 未结 5 2044
旧时难觅i
旧时难觅i 2020-12-20 04:16

in my activity, i have three lists. after running the application, the screen is not scroll-able. i can scroll the list which is on top of others but i can\'t scroll the who

5条回答
  •  一个人的身影
    2020-12-20 04:34

    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));
    }
    

提交回复
热议问题