Search code examples
androidlayoutandroid-imageviewexpandablelistviewandroid-scrollview

Image and ExpandableListView in the same Scroll View


I have a layout which contains a title, an image and the a ExpandableListView. My problem is that while the title doesn't have to scroll, I would like the image and the ExpandaleListView to be one unique block that can be scrolled.

Until now I cannot see the ExpandibleListView unless I add a height value.

This is my layout code:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/title"/>

</LinearLayout>

    <ScrollView 
                android:layout_width="match_parent"
                android:layout_height="fill_parent"> 
    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical">

    <LinearLayout
                android:id="@+id/userContent"
                android:layout_width="match_parent"
                android:layout_height="175dp"
                android:background="@color/black"
                android:gravity="center_vertical">

                <RelativeLayout
                    android:id="@+id/userDrawer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/transparent" >

                    <ImageView
                        android:id="@+id/ImgDrawer"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:contentDescription="@string/app_name"
                        android:scaleType="centerCrop"
                        android:src="@drawable/ic_user" />

                </RelativeLayout>
            </LinearLayout>

<ExpandableListView
        android:id="@+id/lvExp"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:focusable="false"/>   

</LinearLayout>
</ScrollView>
</LinearLayout>

Solution

  • Solved putting the image into a layout called "header" and then putting this code into the activity:

    final ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.lvExp);
    View header = inflater.inflate(R.layout.header, null);
    elv.addHeaderView(header);