Search code examples
androidandroid-relativelayout

How to set the same height in RelativeLayout?


Below is my xml code:

<RelativeLayout
    android:id="@+id/ib"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:gravity="center" >

    <ImageButton
        android:id="@+id/button_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/tv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/ib"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

The ImageButton ib and TextView tw has different height.
I want the ib and tv had the same height.
That is if height of ib > tv, then set the height of tv same as ib.
If else, then set the height of ib same as tv.
How can I do it?


Solution

  • Use LinearLayout and set ImageButton height to "wrap_content" and for TextView set height to "fill_parent".