Android 如何在RelativeLayout中设置相同的高度?

Android 如何在RelativeLayout中设置相同的高度?,android,android-relativelayout,Android,Android Relativelayout,下面是我的xml代码: <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_alignPare

下面是我的xml代码:

<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>

ImageButton ib和TextView tw的高度不同。
我希望ib和电视具有相同的高度。
也就是说,如果ib的高度>电视,则将电视的高度设置为与ib相同。
否则,请将ib的高度设置为与tv相同。

我怎么做

您需要将
ImageButton
高度设置为
“包装内容”
,并将
文本视图设置为
“填充父项”
。您需要将它们都包装在布局父级中。通过这种方式,它们与相同的布局父级关联。

使用LinearLayout并将
ImageButton
高度设置为
“包裹内容”
,对于
文本视图
将高度设置为
“填充父级”

添加
android:layout\u alignBottom=“@+id/按钮图标”
属性到文本视图

将元素放入线性布局,设置layout\u width=“match\u parent”并添加属性“layout\u weight”=“1”

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="sample text"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="sample text"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="sample text"/>
    </LinearLayout>


但父级相对长度高度为包裹内容。它将导致高度全屏显示?否…RelativeLayout height为wrap_content意味着RelativeLayout height将取决于其中内容(图像按钮、文本视图等)的高度…在RelativeLayout中是否可能?我认为不可能使用RelativeLayout。如果使用相对布局,则必须指定ImageButton的最大高度,这样它就不会将ImageButton拉伸到图像高度。