0

I have a ScrollView that contains a few elements, between the rest, two ListViews. The number of items in each ListView is limited, and I do not want them scrolled. I do, however, want the ScrollView itself to be scrollable, and for some reason, it is not. What is a good solution to this problem?

Almost everywhere I read, it says I should not be putting ListViews inside of a ScrollView, But I need something that looks similar to this layout, and actually functions (Including the titles, that should disappear if the corresponding list is empty and vice versa) -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/light_gray_real">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:elevation="15dp">

    <EditText
        android:id="@+id/etSearch"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:hint="Search values here"
        android:textCursorDrawable="@null"
        android:paddingStart="10dp"
        android:background="@android:color/transparent"/>

    <ImageButton
        android:id="@+id/btnClear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|center"
        android:layout_margin="5dp"
        android:src="@drawable/places_ic_clear"
        android:background="@android:color/transparent"/>
</FrameLayout>


<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:isScrollContainer="true">

        <TextView
            android:id="@+id/tvTitle1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Title 1"
            android:paddingStart="10dp"
            android:paddingTop="2dp"
            android:paddingBottom="2dp"
            android:visibility="gone"/>

        <ListView
            android:id="@+id/listview1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"/>

        <TextView
            android:id="@+id/tvTitle2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Title 2"
            android:paddingStart="10dp"
            android:paddingTop="2dp"
            android:paddingBottom="2dp"
            android:visibility="gone"/>

        <ListView
            android:id="@+id/listview2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"/>
    </LinearLayout>
</ScrollView>

Cookienator
  • 587
  • 5
  • 25

1 Answers1

1

As scrollview and listview are not supporting nested scrolling you can not go with them. Either you can have your custom scrollview for this or

You can go with nestedscrollview instead of scrollview and Recyclerview instead of listview.

mnp343
  • 329
  • 1
  • 6
  • Awesome, this works! I switched to NestedScrollView + RecyclerViews. The scrolling itself was a bit awkward, but this solved it really easily - http://stackoverflow.com/questions/37301724/recyclerview-inside-nested-scrollview-scroll-but-does-not-fast-scroll-like-norma – Cookienator May 09 '17 at 14:30
  • To remove that 'bit awkward' , you can set recyclerview.setNestedScrollingeEnabled(false). on each small recyclerview. – mnp343 May 09 '17 at 14:50