views:

276

answers:

2

I have a list view and want to put stuff both above(on the y axis) and below(y axis) it including images, text views, and a row of buttons. Below is a simplified version of what I am creating. Unfortunately the list covers(i.e. above on the z axis) the header so the header text is not visible instead of being underneath (on the y axis)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">

    <TextView android:id="@+id/footer" 
        android:text="footer"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_alignParentBottom="true"
        />

    <ListView  android:id="@+id/list_view" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:layout_above="@id/footer"
        android:background="#ff9999ff"/>

    <TextView android:id="@+id/header" 
        android:text="header"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_alignParentTop="true"
        android:layout_above="@id/list_view"
        android:baselineAlignBottom="false"
        />

</RelativeLayout>

Here is the corresponding Activity class:

public class SampleListActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_activity);

    }
}
+1  A: 

If you are targeting Android 1.6 and higher, add an android:layout_below="@id/header" to your existing attributes on the ListView.

If you are still targeting Android 1.5, you will need to make that android:layout_below="@+id/header" and perhaps remove the + sign from the current android:id="@+id/header" attribute in the TextView.

RelativeLayout, as of 1.6, supports forward-references to other widgets, so long as the first occurrence of the ID value has the + sign.

CommonsWare
A: 

I couldn't get relative layout to work in Android 1.5 but I did get Linear Layout to work. Below is my solution:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:orientation="vertical">

    <TextView android:id="@+id/header" 
        android:text="header"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="0"
        />
    <ListView  android:id="@+id/list_view" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:background="#ff9999ff"
        android:layout_weight="1"/>

    <TextView android:id="@+id/footer" 
        android:text="footer"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="0"
        />
</LinearLayout>
Jay Askren