views:

38

answers:

2

I have the following layout in my xml file:

<RelativeLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent">

    <FrameLayout android:id="@+id/logoLayout"  
                 android:layout_width="fill_parent"
             android:layout_height="wrap_content">
          -- some images
    </FrameLayout>


    <RelativeLayout android:layout_width="fill_parent" 
                    android:layout_height="wrap_content" 
                    android:gravity="center" 
                    android:orientation="vertical"
                    android:layout_below="@+id/logoLayout">

               Button 1
               Button 2
               Button 3
               Button 4

    </RelativeLayout>

    <RelativeLayout android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dip"
            android:layout_alignParentBottom="true">

                 Button 5
    </RelativeLayout>

<RelativeLayout>

Maybe I didn't do it in the best way. What I want: have the Layout that contains the 4 buttons to use the entire space between the top and bottom layout, and I want to have the button equally arranged in the layout.

Something like this:http://img16.imageshack.us/i/androidq.png/

I add the whole layout code:

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


    <!--The header of the page-->
        <FrameLayout android:id="@+id/logoLayout" 
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content">        

             <ImageView android:id="@+id/logoBackground" 
                        android:src="@drawable/logo_background_small"
                        android:layout_width="fill_parent" 
                        android:layout_height="wrap_content"/>

             <ImageView android:id="@+id/logoImage" 
                        android:src="@drawable/logo_small"
                        android:layout_width="wrap_content" 
                        android:layout_height="wrap_content" 
                        android:layout_gravity="left"
                        android:gravity="center"
                        android:padding="3dip"/>  

             <TextView android:layout_width="fill_parent" 
                       android:layout_height="wrap_content" 
                       android:text="@string/tracks"
                       android:layout_gravity="center"
                       android:gravity="right"
                       android:textSize="22dip"
                       android:textColor="#ffffff"
                       android:padding="3dip">
             </TextView>              

        </FrameLayout>


        <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
                         android:layout_width="fill_parent" 
                         android:layout_height="wrap_content" 
                         android:gravity="center" 
                         android:orientation="vertical"
                         android:layout_below="@+id/logoLayout"> 

                            <Button android:id="@+id/btn1"
                                    android:layout_height="wrap_content" 
                                    android:layout_width="250dip" 
                                    android:drawableLeft="@drawable/img_small_btn_look_around"
                                    android:background="@drawable/main_long_menu_button"
                                    android:text="@string/btn1" 
                                    android:textSize="18dip"
                                    android:textColor="#ffffff"
                                    android:layout_marginTop="20dip"
                                    android:onClick="btnMyTracksOnClick">
                            </Button> 

                            <Button android:id="@+id/btn2"
                                    android:layout_height="wrap_content" 
                                    android:layout_width="250dip" 
                                    android:drawableLeft="@drawable/img_small_btn_look_around"
                                    android:background="@drawable/main_long_menu_button"
                                    android:text="@string/btn2" 
                                    android:textSize="18dip"
                                    android:textColor="#ffffff"
                                    android:layout_marginTop="20dip"
                                    android:layout_below="@+id/btn1">
                            </Button>

                            <Button android:id="@+id/btn3"
                                    android:layout_height="wrap_content" 
                                    android:layout_width="250dip" 
                                    android:drawableLeft="@drawable/img_small_btn_look_around"
                                    android:background="@drawable/main_long_menu_button"
                                    android:text="@string/btn3" 
                                    android:textSize="18dip"
                                    android:textColor="#ffffff"
                                    android:layout_marginTop="20dip"
                                    android:layout_below="@+id/btn2">
                            </Button>

                            <Button android:id="@+id/btn4"
                                    android:layout_height="wrap_content" 
                                    android:layout_width="250dip" 
                                    android:drawableLeft="@drawable/img_small_btn_look_around"
                                    android:background="@drawable/main_long_menu_button"
                                    android:text="@string/btn4" 
                                    android:textSize="18dip"
                                    android:textColor="#ffffff"
                                    android:layout_marginTop="20dip"
                                    android:layout_below="@+id/bt3">
                            </Button>
        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dip"
                        android:layout_alignParentBottom="true">

                        <Button android:layout_width="90dip" 
                                android:layout_height="wrap_content"
                                android:textSize="20dip"
                                android:textColor="#ffffff"
                                android:layout_alignParentLeft="true"
                                android:background="@drawable/sett_menu_button"
                                android:text="@string/back" 
                                android:layout_marginLeft="3dip"/> 

         </RelativeLayout>

    </RelativeLayout>
A: 

Step #1: Change your middle RelativeLayout to a LinearLayout.

Step #2: Add android:layout_above="..." to the LinearLayout, where ... is an android:id you assign to the bottom RelativeLayout.

Step #3: Set each of the buttons' height to 0px and weight 1 to one for equal sizing.

CommonsWare
I have tried what you said but it didn't worked. I attached the whole initial code, maybe I missed something when exposed the problem. Thank you for your time
Alin
+1  A: 

Try changing

<RelativeLayout android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:gravity="center" 
                android:orientation="vertical"
                android:layout_below="@+id/logoLayout">

           Button 1
           Button 2
           Button 3
           Button 4

</RelativeLayout>

to:

<LinearLayout android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:gravity="center" 
                android:orientation="vertical"
                android:layout_below="@+id/logoLayout">

           <!-- example button -->
           <Button android:layout_width="fill_parent" 
                android:layout_height="wrap_content" android:layout_weight="1"></Button>
</LinearLayout>

the layout_weight should evenly space it out

Hope it works

zsniper