Search code examples
androidandroid-layoutandroid-relativelayout

Android: 2 relative layout divided in half screen


I tried many times to draw 2 Relative layout aligned horizontally and divided in half screen.

enter image description here

I design the image with paint to explain a bit better what i mean.

Any suggestion?


Solution

  • You can put these 2 RelativeLayouts inside a LinearLayout with horizontal orientation, then use the weight for both RelativeLayouts. This will divide the LinearLayout in 2 equal parts.

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">
        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1">
       </RelativeLayout>
       <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1">
       </RelativeLayout>
    </LinearLayout>