Android, How to add ScrollView to the screen with some list items?

In my activity, I have three lists. After starting the application, the screen does not scroll. I can scroll a list that is on top of others, but I can not scroll the whole page. I tried adding ScrollViewxml to my layout, but lint says that "Scrolling vertically ScrollView should not contain another widget with vertical scrolling (ListView)."

How to make my screen scrollable?

+2
source share
5 answers

Try this way

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <LinearLayout android:id="@+id/GlobalLayout" 
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical" >

        <ListView android:id="@+id/ListView1"
                  android:choiceMode="multipleChoice"
                  android:layout_height="100dip"
                  android:layout_width="fill_parent" />
       <ListView android:id="@+id/ListView2"
                  android:choiceMode="multipleChoice"
                  android:layout_height="100dip"
                  android:layout_width="fill_parent" />
       <ListView android:id="@+id/ListView3"
                  android:choiceMode="multipleChoice"
                  android:layout_height="100dip"
                  android:layout_width="fill_parent" />

    </LinearLayout>

</ScrollView>
+2
source

enter image description here

<ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ListView
                android:id="@+id/listView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" >
            </ListView>

        </LinearLayout>

    </ScrollView>

Scrollview supports a single child layout, so create a scroll list to get what you want.

+1
source

, , , listview scrollview . visibilty, HIDE , , VISIBLE . listview . ,

+1

, 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));
}
+1

, , , . xml layououts listview, .

    View headerView = View.inflate(this, R.layout.layout_name, null);
    lv.addHeaderView(headerView);

use it before configuring the adapter. lv - listview.

0
source

All Articles