Question

My problem is i cannot show the two button in my layout under the listview. Below i have a listview within a relativelayout. i have a second relativelayout that contains 2 button. the buttons seem to show on top of the list whereas i would like them below the list.

how can i do this? i've tried setting the 'android:layout_below' in the second RRlayout giving the first layout as the anchor.

Thanks in advance.

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

    <TextView
        android:id="@+id/textviewcarername"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/blue_alpha_background"
        android:gravity="center"
        android:text="Rota "
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF" />

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/carerdetailsfragrellayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textviewcarername"
        android:background="@drawable/textviewbg"

        android:padding="10dp" >

        <ListView
            android:id="@+id/android:list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:cacheColorHint="#0000"
            android:divider="#700000ff"
            android:dividerHeight="4px" >
        </ListView>
    </RelativeLayout>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"

         >

        <Button
            android:id="@+id/buttonprevious"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Previous" />

        <Button
            android:id="@+id/buttonnext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Next" />
    </RelativeLayout>

</RelativeLayout>
Was it helpful?

Solution

This layout should do the job

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >
    <!-- Header -->
    <TextView
        android:id="@+id/textviewcarername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/blue_alpha_background"
        android:gravity="center"
        android:text="Rota "
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFFFFF"
    />
    <!-- Bottom Layout (Footer) -->
    <RelativeLayout
        android:id="@+id/rlFooter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
         >
        <Button
            android:id="@+id/buttonprevious"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Previous"
        />
        <Button
            android:id="@+id/buttonnext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Next"
        />
    </RelativeLayout>
    <!-- ListView -->
    <RelativeLayout
        android:id="@+id/carerdetailsfragrellayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/textviewcarername"
        android:layout_above="@id/rlFooter"
        android:background="@drawable/textviewbg"
        android:padding="10dp"
        >
        <ListView
            android:id="@+id/android:list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cacheColorHint="#0000"
            android:divider="#700000ff"
            android:dividerHeight="4px"
        />
    </RelativeLayout>
</RelativeLayout>

Note that I moved the bottom layout BEFORE the one containing the ListView and assigned it an id, so it could be referred by the ListView container

I also removed the extra namespace definitions

[EDIT]

I now changed the ListView and its container wrap_content to match_parent, in order to fill the remaining space. The ListView should now fit perfectly (I forgot that particular)

[EDIT 2]

You might want to remove the RelativeLayout that encloses the ListView and add its attributes to the ListView itself, to help flattening your design - for performance increase (as little as it may be).

OTHER TIPS

Try this..

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

    <TextView
        android:id="@+id/textviewcarername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Rota "
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000000" />

    <RelativeLayout
        android:id="@+id/carerdetailsfragrellayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:padding="10dp" >

        <ListView
            android:id="@+id/android:list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:cacheColorHint="#0000"
            android:divider="#700000ff"
            android:dividerHeight="4px" >
        </ListView>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/buttonprevious"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Previous" />

        <Button
            android:id="@+id/buttonnext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Next" />
    </RelativeLayout>

</LinearLayout>

Give an id to the RelativeLayout which contains Buttons as android:id="@+id/button_panel" and add the attribute android:layout_above="@+id/button_panel" in the RelativeLayout which contains ListView as below...

<TextView
    android:id="@+id/textviewcarername"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/blue_alpha_background"
    android:gravity="center"
    android:text="Rota "
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#FFFFFF" />

<RelativeLayout
    android:id="@+id/carerdetailsfragrellayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/textviewcarername"
    android:background="@drawable/textviewbg"
    android:layout_above="@+id/button_panel"
    android:padding="10dp" >

    <ListView
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:cacheColorHint="#0000"
        android:divider="#700000ff"
        android:dividerHeight="4px" >
    </ListView>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/button_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <Button
        android:id="@+id/buttonprevious"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Previous" />

    <Button
        android:id="@+id/buttonnext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Next" />
</RelativeLayout>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top