I create a sliding menu that opens to the side. The menu has ScrollViewwith LinearLayoutinside it for general layout and scrolling. In addition, to display the menu items, I have a list view inside LinearLayout, which means that the view hierarchy has the form:
ScrollView
LinearLayout
ListView
I am trying to populate with a ListViewspecial adapter that gets its data from an array. But surprisingly, when I fill in the data, it ListViewdoes not grow to show all its children, even if it is set to wrap_content. Instead, it displays only one item, but I can scroll this item to see the rest of the items.
I assume it is already in ScrollView, but I don't need the scroll function ListView. I just want it to display all the menu items, and let it ScrollViewtake care of scrolling. Menu items will not grow more than 10, so I'm not worried about memory usage right now.
Is there a way, possibly an extension ListView, to disable scrolling and make it really wrap_content?
XML format:
<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>
source
share