Stretching two layouts in parent layout

192 views Asked by At

I am trying to achieve that the two nesting relative layouts take up an equal amount of space AND for the to fill out the whole width of the screen. All parent layouts have fillparent set on width. The graphical view in Eclipse looks fine, but my HTC disagrees - it glues them together (I'm fine with that) but it also shifts them to the left. I want them stretched.

  <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >

            <ImageButton
                android:id="@+id/button_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:src="@drawable/button_1_active" >
            </ImageButton>

            <TextView
                android:id="@+id/TextView01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/partners_info"
                android:textColor="@color/white"
                android:textStyle="bold" >
            </TextView>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/relativeLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             >

            <ImageButton
                android:id="@+id/button_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:src="@drawable/button_2_inactive" >
            </ImageButton>

            <TextView
                android:id="@+id/TextView02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/partners_map"
                android:textColor="@color/white"
                android:textStyle="bold" >
            </TextView>
        </RelativeLayout>
    </LinearLayout>
3

There are 3 answers

0
user On BEST ANSWER

For the two ImageButton try to set the layout_width attribute to fill_parent and then also add:

    android:scaleType="fitXY"
1
berlindev On

To get them using equal space you would have to set layout_weight to equal numbers.

3
NagarjunaReddy On

use this layout_weight=1. in two RelativeLayout

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        >