cdonner
cdonner

Reputation: 37668

Scrollable Android ListView in TableView Row

I have the following layout for a dialog:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/categorylist" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0"> 
    <TableRow>
        <ListView 
            android:id="@+id/categorylistview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:isScrollContainer="true"
            android:scrollbars="vertical"
            android:scrollbarStyle="insideOverlay"
        />
    </TableRow>
    <TableRow>
        <TextView 
            android:text="New Category" 
            ...
        </TextView>
    </TableRow>
    <TableRow>
        <EditText 
            android:id="@+id/NewCategoryEditText" 
            ...
        </EditText>
    </TableRow>
    <TableRow>
        <Button 
            android:id="@+id/newcategorybutton"
            ...
        />
    </TableRow>
</TableLayout>      

I would like the Listview to grow until the available space is used, then scroll as it coninues to grow. This works fine when the table row with the Listview is the last one in the TableLayout:

alt text
(source: heeroz.com)

However, having the Add button at the top of the list is not very intuitive. When I move the "fixed" table rows to the bottom, the ListView will push them off the screen once it grows to a point where it should scroll. The ListView will only then begin to scroll when there is nothing else left that can be pushed off the screen:

alt text
(source: heeroz.com)

How can I change my layout so that the table rows with the button and the EditText view remain visible?

Upvotes: 1

Views: 6193

Answers (1)

Rich Schuler
Rich Schuler

Reputation: 41972

Is there a particular reason you're using a TableLayout instead of a LinearLayout with android:orientation="vertical"? If you use the LinearLayout you can specify android:layout_weight="1" on the ListView and you should get the results you want.

Upvotes: 4

Related Questions