ListView inside of LinearLayout won't grow to show all children

android, android-layout, android-listview

Solution

One golden rule is not to put a View with scrolling ability into another.

If you don't want the scrolling functionality of `ListView` then you'd be better off using something like a `TableLayout` instead of `ListView` and dynamically add `TableRows`.

Problem

I'm building up a sliding menu which opens from the side. In the menu, there is a `ScrollView` with a `LinearLayout` inside it for general layout and scrolling. Plus, for displaying the menu items, I have a list view inside the `LinearLayout`, meaning that the view hierarchy goes like: ``` ScrollView LinearLayout ListView ``` I'm trying to populate the `ListView` with a custom adapter, which gets its data from an array. But surprisingly when I populate the data, the `ListView` doesn't grow to show all of its children, even with being set to `wrap_content`. Instead it just displays one item, but I'm able to scroll over that item to see the rest of the items. I'm guessing it's because it is already in a `ScrollView`, but I don't want the scroll functionality of the `ListView`. I just want it do display all the menu items, and let the `ScrollView` take care of the scrolling. The menu items won't grow over 10, so I'm not worried about memory usage right now. Is there a way, possibly by extending the `ListView`, to disable the scrolling and make it really do `wrap_content`? Layout XML: ``` <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#2e2e2e"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="20dp" android:gravity="center_horizontal" android:orientation="vertical"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/menu_profile_picture" android:layout_width="100dp" android:layout_height="100dp" android:layout_marginTop="10dp" android:src="@drawable/default_profile_picture" app:border_color="#FFF" app:border_width="2dp"/> <com.devspark.robototextview.widget.RobotoTextView android:id="@+id/menu_user_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="John Doe" android:textColor="#FFF" android:textSize="22sp" app:typeface="roboto_thin"/> <com.devspark.robototextview.widget.RobotoTextView android:id="@+id/menu_logged_in" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="LOGGED IN" android:textColor="#1e4472" android:textSize="15sp" app:typeface="roboto_light"/> <ListView android:id="@+id/menu_items" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginTop="20dp" /> <ImageView android:id="@+id/menu_logout_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:src="@drawable/ic_logout"/> <com.devspark.robototextview.widget.RobotoTextView android:id="@+id/menu_logout_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:text="LOG OUT" android:textColor="#e20202" android:textSize="15sp" app:typeface="roboto_light"/> </LinearLayout> </ScrollView> ```

Original source