tags:

views:

30

answers:

3

I am attempting to make a ListView inside a table consume all of the available vertical space minus the space needed for an EditText control.

I have set every attribute I can think of here to make it work:

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

 <TableRow android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:background="#FF0000">
    <ScrollView android:layout_width="fill_parent"
        android:layout_height="fill_parent">
     <ListView android:id="@+id/conversation"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:drawSelectorOnTop="false"/>
    </ScrollView>
 </TableRow>

 <TableRow android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:background="#00FF00">
     <EditText android:id="@+id/messagetext" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
        android:imeOptions="actionDone"/>
 </TableRow>

I must be missing something, as the result is a fully filled horizontal, but both the ListView and EditText appear to be behaving as if their attributes were wrap_content.

A: 

I appear to have been missing an attribute android:layout_weight on the top TableRow. Evidently, anything over 2 makes it consume the rest of the vertical real estate. Can anybody explain why the special treatment for TableRows?

Jon
You don't need a value of 2 four your layout_weight. If it is the only element attributed with it then you can assign it a value of 1.
Octavian Damiean
A: 

Don't use ListView inside of ScrollView, because ListView manages it's own vertical scrolling. Doing so will kill all optimization's done by the ListView

And don't anwser to your own posts. Rather edit your initial questions or add an comment.

Tseng
It is perfectly valid to answer your own question if you've solved it.
Octavian Damiean
+1  A: 

Is there a particular reason you're using a TableLayout? I'm not very familiar with using them yet, but what you're trying to accomplish is simple with a RelativeLayout. Also, you don't need to place the ListView within a ScrollView, the ListView handles scrolling on its own. Here is an example of how you could accomplish this using a RelativeLayout:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText
        android:id="@+id/message_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
        android:imeOptions="actionDone"
        android:alignParentBottom="true"
        />
    <ListView
        android:id="@+id/conversation"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FF0000"
        android:layout_above="@id/message_text"
        />
</RelativeLayout>

This way, you first define the EditText to take up a certain amount of space (wrap_content, in this instance). Then, you define the ListView to fill the remaining space with fill_parent. Adding android:layout_above="@id/message_text" aligns the bottom edge of the ListView with the top edge of the EditText view.

kcoppock