[英]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.