Search code examples
androidxmlheightandroid-relativelayout

Two RelativeLayouts, with the same height


I have two RelativeLayouts (one next to each other).
A white RelativeLayout and a red one.

As the amount of the text in the white side increases, I want the the red side to grow.


Solution

  • Have you tried setting the red RelativeLayout android:layout_alignBottom to the id of the white RelativeLayout?

    I'm not sure how your text is being input into the white layout but if you are dealing with an EditText inside of the white RelativeLayout then this should make sure that the red side is always the same height as the white as new text is added causing the white side to grow in height.

    Something along the lines of this:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin">
    
        <RelativeLayout
            android:id="@+id/red"
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:layout_alignBottom="@+id/white"
            android:background="#FF0000">
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/white"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@id/red"
            android:layout_toRightOf="@id/red"
            android:background="#FFFFFF">
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="false"
                />
    
        </RelativeLayout>
    
    </RelativeLayout>