Jul
Jul

Reputation: 549

how to align RelativeView to stick to the bottom

I have a fairly large layout file which are part of an TabHost, my problem is that the last RelativeLayout (@id/footbar) won't stick to the bottom of my view no matter what attribute I use, it seems.

Please give me an idea to realize that. I want the ListView to be between the placeholder (hline) and the footbar.

Currently the footbar sticks to the List which is aligned correctly at the top, but extends with its contents. When I choose the list to have a height of "match_parent" or "fill_parent" it takes all the space to the bottom and moves footbar out of the view :(

BTW: Is there a way to get the scaled ImageButton to fit to the height of the spinner or the way round?

Thank's in advance

Here's the listing:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/abrtimer">

    <TextView android:id="@+id/username_timer"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:layout_alignParentTop="true"
              android:layout_alignParentRight="true"
    />

    <ImageView android:id="@+id/hline"
               android:layout_width="fill_parent"
               android:layout_height="2dip"
               android:background="#544444"
               android:layout_below="@id/username_timer" />

    <RelativeLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_below="@id/hline"
                  android:orientation="vertical">
         <ExpandableListView android:id="@+id/timerList"
                            android:layout_height="wrap_content"
                            android:layout_width="match_parent"
                            android:drawSelectorOnTop="true"
                            android:gravity="top"/>

         <LinearLayout android:orientation="horizontal"
                     android:layout_below="@id/timerList"
                     android:id="@+id/footbar"
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:layout_alignParentBottom="true"
                     android:gravity="bottom"
                     android:weightSum="10">

             <Spinner android:layout_height="wrap_content"
                android:id="@+id/projectSpinner"
                android:layout_width="fill_parent"
                android:layout_gravity="left"
                android:layout_weight="8"/>
            <ImageButton android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@android:drawable/ic_menu_add"
                android:id="@+id/addButton"
                android:scaleType="centerCrop"
                android:layout_gravity="right"
                android:layout_weight="2"/>      
         </LinearLayout>
     </RelativeLayout>

</RelativeLayout>

Upvotes: 0

Views: 1075

Answers (1)

Michael
Michael

Reputation: 54705

I thinks this code is what you need. It's simplified a little. You don't really need to use RelativeLayouts to implement this layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/abrtimer">

    <TextView android:id="@+id/username_timer"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="top|right" />

    <ImageView android:id="@+id/hline"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:background="#544444" />

    <ExpandableListView android:id="@+id/timerList"
        android:layout_height="0dip"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:drawSelectorOnTop="true" />

    <LinearLayout android:orientation="horizontal"
        android:layout_below="@id/timerList"
        android:id="@+id/footbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:weightSum="10">

        <Spinner android:layout_height="wrap_content"
            android:id="@+id/projectSpinner"
            android:layout_width="fill_parent"
            android:layout_gravity="left"
            android:layout_weight="8"/>
        <ImageButton android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_add"
            android:id="@+id/addButton"
            android:scaleType="centerCrop"
            android:layout_gravity="right"
            android:layout_weight="2"/>      
    </LinearLayout>
</LinearLayout>

Upvotes: 2

Related Questions