Krishna Gangaraju
Krishna Gangaraju

Reputation: 529

Android: adding components to RelativeLayout

in My screen, i want to have Hearder(specifically image) on top, and List, and at bottom i want to have small imagebuttons (like youtube,facebook).

I'm using RelativeLayout.. first two are displaying correctly, last one not display at all on the screen, can anyone help here.

my layout file looks like this

<RelativeLayout>
    <image></image>
    <ListView></ListView>
    <RelativeLayout>
        <ImageButton></ImageButton>
    </RelativeLayout>
</RelativeLayout>

Upvotes: 2

Views: 1208

Answers (1)

rekaszeru
rekaszeru

Reputation: 19220

In a RelativeLayout it matters in which order you add the child views (since the latter can be bound to the ones added previously).
I think this is the problem in your layout, you have a fill_parent/match_parent high view already inside (the ListView), and there is no room for the footer.

You should change the order of your views inside the RelativeLayout:

  1. first you should add the header view (and bind it to the top: android:align_parent_top="true"), then
  2. the footer with buttons (and bind it to the bottom: android:align_parent_bottom="true"), and
  3. the ListView which should fill up the empty space will go in as the thirds view, with android:layout_below="header_view" and adroid:layout_above="footer_view"`

Your layout would then look like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
    <image android:id="@+id/header" 
        android:layout_alignParentTop="true"></image>
    <RelativeLayout android:id="@+id/footer"
        android:layout_alignParentBottom="true">
        <ImageButton></ImageButton>
    </RelativeLayout>
    <ListView
        android:layout_below="@id/header" 
        android:layout_above="@id/footer"></ListView>
</RelativeLayout>

Upvotes: 2

Related Questions