0

I have an Android layout. I've set a listener like list.setOnItemClickListener. Everything seems to work fine.

In the line below:

<ScrollView android:layout_width="fill_parent"
            android:layout_height="wrap_content">

If I change android:layout_height from wrap_content to fill_parent it doesn't work anymore (the item from my list cannot be selected).

It works only if it's set to wrap_content. Why does this happen?

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/tabhost"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <TabWidget android:id="@android:id/tabs"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
            />
    <FrameLayout android:id="@android:id/tabcontent"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
            >
        <ListView android:id="@+id/restaurants"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                />
        <ScrollView android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

            <TableLayout android:id="@+id/details"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:stretchColumns="1"
                         android:shrinkColumns="1"
                         android:paddingTop="4dip"
                    >
                <TableRow>
                    <TextView android:text="@string/name" />
                    <EditText android:id="@+id/name" />
                </TableRow>
                <TableRow>
                    <TextView android:text="@string/address" />
                    <EditText android:id="@+id/addr" />
                </TableRow>
                <TableRow>
                    <TextView android:text="Type:" />
                    <RadioGroup android:id="@+id/types">
                        <RadioButton android:layout_height="wrap_content"
                                     android:layout_width="wrap_content"
                                     android:id="@+id/take_out"
                                     android:text="@string/takeout"
                                     android:checked="true"
                                />

                        <RadioButton android:layout_height="wrap_content"
                                     android:layout_width="wrap_content"
                                     android:id="@+id/sit_down"
                                     android:text="@string/sitdown"
                                />
                        <RadioButton android:layout_height="wrap_content"
                                     android:layout_width="wrap_content"
                                     android:id="@+id/delivery"
                                     android:text="@string/delivery"
                                />
                    </RadioGroup>
                </TableRow>

                <TableRow>
                    <TextView android:text="@string/notes" />
                    <EditText android:id="@+id/notes" />
                </TableRow>

                <Button android:id="@+id/save"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/save"
                        />
            </TableLayout>
        </ScrollView>
    </FrameLayout>
</LinearLayout>
</TabHost>
double-beep
  • 5,031
  • 17
  • 33
  • 41
Hélène
  • 377
  • 1
  • 5
  • 13
  • it wont work as using `fill_parent` will try to fill all area inside `FrameLayout`, however there exist also a `ListView android:id="@+id/restaurants"` included. Maybe a solution will be to but `ScrollView` in another `RelativeView` and place it below `ListView android:id="@+id/restaurants"` – hrskrs Feb 11 '15 at 11:50
  • Do a test: change listView background color to black and the ScrollView background color to red. Look what view your are working. It can be fill all space above listView. – Franklin Hirata Feb 11 '15 at 12:21

2 Answers2

0

fill_parent (deprecated and renamed MATCH_PARENT in API Level 8 and higher)

Setting the layout of a widget to fill_parent will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dockstyle of a Windows Form Control to Fill.

Setting a top level layout or control to fill_parent will force it to take up the whole screen.

wrap_content

Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.

There's some details in the Android code documentation here.

Community
  • 1
  • 1
Machado
  • 14,105
  • 13
  • 56
  • 97
0

Your ScrollView is taking up all avaliable space inside your ListView that can populate on your screen, basically covering it up.

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView. --From http://developer.android.com/reference/android/widget/ScrollView.html

DevJem
  • 656
  • 1
  • 13
  • 21