2

I have problem with ExpandableListView in ScrollView. I have in my app this layout:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/carType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text=" "
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TableLayout
        android:id="@+id/infoTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/carType"
        android:stretchColumns="*" >

        <TableRow>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:paddingBottom="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:text="@string/tire_replacement"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/tirereplacement"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:text="@string/add_date" />
        </TableRow>

           //...rows...

    </TableLayout>

    <ExpandableListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/infoTable" >
    </ExpandableListView>
</RelativeLayout>

Looks like this:

enter image description here

But I can´t see whole ExpandableListView. Only one group header row is visible (there shloud be two) and If I expand it, I can´t see the child. If I remove android:layout_below="@+id/infoTable, there is whole ExpandableListView:

enter image description here

Do you know, where can be problem??

Pepa Zapletal
  • 2,879
  • 3
  • 39
  • 69
  • Do not nest views which scroll along the same axis. Your ScrollView and ExpandableListView both scroll vertically. – Karakuri Apr 28 '14 at 20:09
  • Yes, but do you have tip how can I edit the layout? I need somehow ExpandableListView below the TableLayout... – Pepa Zapletal Apr 28 '14 at 20:16
  • No, it really depends on your design. I'm just telling you that having nested scrolling components that scroll along the same axis has inherently bad behavior on Android and advising against it. How you design your layout with this fact in mind is entirely up to you. – Karakuri Apr 28 '14 at 20:17

2 Answers2

3

Maybe this will help you. put a ListView in a ScrollView and fix the height of ListView according to it's item How can I put a ListView into a ScrollView without it collapsing?

Community
  • 1
  • 1
Ginsan
  • 344
  • 2
  • 8
1
// try this way,hope this will help you...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.70"
        android:fillViewport="true" >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/carType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:text=" "
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TableLayout
                android:id="@+id/infoTable"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/carType"
                android:stretchColumns="*" >

                <TableRow>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="right"
                        android:paddingBottom="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="5dp"
                        android:text="@string/tire_replacement"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/tirereplacement"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:clickable="true"
                        android:text="@string/add_date" />
                </TableRow>

                //...rows...

            </TableLayout>
        </RelativeLayout>
    </ScrollView>
    <ExpandableListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.30">
    </ExpandableListView>
</LinearLayout>
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67