Search code examples
androidscrollview

How to scroll a layout that contains 2 listviews and a textview in android


In my activity page ,there is a layout which contains one listview at top(listview1),below listview1 ,there is a textrview and below this testview,second listview is placed. I want to scroll the full layout.

Below is the sample code

<ScrollView
    android:id="@+id/scrol1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/linearLayout1"
    android:layout_marginTop="15dp" android:scrollbars="vertical" android:isScrollContainer="true">

    <RelativeLayout
        android:id="@+id/relativeLayout4"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/linearLayout1"
        android:layout_marginTop="15dp" >

        <ListView
            android:id="@+id/lstMore"
            android:layout_width="fill_parent"
            android:layout_height="200dp"
            android:divider="@null"
            android:fadingEdge="none"
            android:footerDividersEnabled="false" android:dividerHeight="0dp" android:cacheColorHint="#00000000">
        </ListView>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Learn More"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black"
            android:textStyle="bold" android:layout_below="@id/lstMore"/>

        <ListView
            android:id="@+id/lstMoreBottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fadingEdge="none" android:layout_below="@id/textView2" android:divider="@null" android:dividerHeight="0dp" android:cacheColorHint="#00000000">
        </ListView>

    </RelativeLayout>
</ScrollView>

Solution

  • In my experience it's not possible to multiple ListViews in a ScrollView. You try to place two scrollable widgets in another scrollable widget.

    What you should do is inflate different layouts in your list adapter and have a single ListView without the ScrollView.