varun kumar
varun kumar

Reputation: 21

How to place listview inside a scroll view

I have a RelativeLayout and below that i have a ListView. I have to place these inside a ScrollView. Any help will be deeply appreciated.

Upvotes: 0

Views: 205

Answers (3)

Paul Harris
Paul Harris

Reputation: 5809

Don't do it. What exactly are you trying to achieve? It had been mentioned here (and everywhere else) this is not a good idea because the scrolling mechanisms get confused as they both want to scroll. Ignoring you however have a listview that is massive then you have missed the major performance gain of using a listview and might swell be using a table layout and add rows.

Upvotes: 0

Avadhani Y
Avadhani Y

Reputation: 7626

ScrollView can be set only for a single Layout. So place the widgets which u want to scroll in a single layout as below:

<ScrollView
    android:id="@+id/scrView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     >

    <RelativeLayout
        android:id="@+id/rltvLyt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ListView
            android:id="@+id/lstView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="20sp" />
    </RelativeLayout>
</ScrollView>

Upvotes: 0

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21181

You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView

Upvotes: 2

Related Questions