繁体   English   中英

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

[英]How to set the same height in 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_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> tv的高度,那么将电视的高度设置为与ib相同。
如果不然,那么设置ib的高度与tv相同。
我该怎么做?

android:layout_alignBottom="@+id/button_icon"属性添加到textview

使用LinearLayout并将ImageButton高度设置为"wrap_content" ,将TextView设置高度设置为"fill_parent"

您需要使ImageButton高度"wrap_content" ,并使TextView只是"fill_parent" 您需要将它们都包装在布局父级中。 这样,它们与相同的布局父级相关联。

将您的元素放入LinearLayout,设置layout_width =“match_parent”并添加属性“layout_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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM