Scorpion
Scorpion

Reputation: 6901

ScrollView and RelativeLayout scrolling issue for ExpandableListView

I am having below layout which displays contact details and also have one expandable list. But the problem is that Expandable List View is fixed but I have given it fill_parent for height so it must take full height which is available. Also the scroll view is applied to list only instead of the whole layout. If anyone has any idea please kindly help me.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:scrollbars="vertical|horizontal" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >

        <RelativeLayout
            android:id="@+id/vsHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/header" >

            <Button
                android:id="@+id/btnHome"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@drawable/home"
                android:onClick="btnHomeClick" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/contactheader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/vsHeader"
            android:padding="5dip" >

            <TextView
                android:id="@+id/txtContactName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dip"
                android:text="Hello Taxi"
                android:textColor="@color/autoText"
                android:textSize="@dimen/text_size_large"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/img_address"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtContactName"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/address" />

            <TextView
                android:id="@+id/txt_Address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtContactName"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@+id/img_address"
                android:maxLines="5"
                android:singleLine="false"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_phone"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txt_Address"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/contact_no" />

            <TextView
                android:id="@+id/txtPhone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txt_Address"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_phone"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_mobile"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtPhone"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/mobile" />

            <TextView
                android:id="@+id/txtmobilenumber"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtPhone"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_mobile"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_web"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtmobilenumber"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/www" />

            <TextView
                android:id="@+id/txtweb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtmobilenumber"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_web"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_email"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtweb"
                android:layout_marginBottom="15dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/mail" />

            <TextView
                android:id="@+id/txtemail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtweb"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_email"
                android:textColor="@color/autoText" />

            <Button
                android:id="@+id/btn_rate_it"
                android:layout_width="150dip"
                android:layout_height="wrap_content"
                android:layout_below="@id/img_email"
                android:layout_centerHorizontal="true"
                android:background="@drawable/greenbutton"
                android:text="@string/rate_it"
                android:textColor="#ffffff" />
        </RelativeLayout>

        <ExpandableListView
            android:id="@+id/expandable_list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/contactheader"
            android:layout_marginTop="10dip"
            android:groupIndicator="@drawable/group_indicator" />
    </RelativeLayout>

</ScrollView>

IMAGE :- You can see that only listview has scroll so when you scroll the UI become somewhat ugly. I don't want to do like this. I want that whole layout scroll.

enter image description here

Upvotes: 2

Views: 2375

Answers (1)

Alireza Hassani
Alireza Hassani

Reputation: 21

I know it is too late but I Wrote for other people that encountering this problem.The problem is when you use ExpandableListView inside Scrollview ExpandableListView height not defined correctly.So I compute height programmatically like this:

//for converting dp to pixel
final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
//when all the headers are Collapse
expListView.getLayoutParams().height=listDataHeader.size()*(int) (43 * scale + 0.5f);

expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

                @Override
                public void onGroupExpand(int groupPosition) {

                    expListView.getLayoutParams().height+=listDataChild.get(listDataHeader.get(groupPosition)).size()*(int) (34 * scale + 0.5f);

                }
            });

            // Listview Group collasped listener
            expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

                @Override
                public void onGroupCollapse(int groupPosition) {
                    expListView.getLayoutParams().height-=listDataChild.get(listDataHeader.get(groupPosition)).size()*(int) (34 * scale + 0.5f);

                }
            });

Upvotes: 2

Related Questions