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