views:

350

answers:

2

So Ive been trying to add a button underneath a listview in android, the problem is that the button does not appear.

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
    android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;

    <ListView
        android:id="@+id/messagelist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="0px"
        android:layout_y="0px">
    </ListView>
    <Button
        android:id="@+id/addbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_x="0px"
        android:layout_y="379px">
    </Button>
</AbsoluteLayout>
A: 

see my response on this question

kosokund
+1  A: 

AbsoluteLayout is deprecated. I would suggest instead that you use a LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;

    <ListView
        android:id="@+id/messagelist"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1">
    </ListView>
    <Button
        android:id="@+id/addbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button">
    </Button>
</LinearLayout>

I'd also suggest reading through the developer docs on layouts for a good introduction.

Mayra
Don't use wrap_content for the ListView height, use 0dip. Wrap_content is very expensive and it won't change the result.
Romain Guy
Woops, I had reversed the layout_width and layout_height in my example. Fixed it.
Mayra
I tried so many things and found your solution. Really thank you for that
Mur Votema