[英]How to set the same height in RelativeLayout?
Below is my xml code: 下面是我的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>
The ImageButton ib and TextView tw has different height. ImageButton ib和TextView tw具有不同的高度。
I want the ib and tv had the same height. 我希望ib和电视具有相同的高度。
That is if height of ib > tv, then set the height of tv same as ib. 那就是如果ib> tv的高度,那么将电视的高度设置为与ib相同。
If else, then set the height of ib same as tv. 如果不然,那么设置ib的高度与tv相同。
How can I do it? 我该怎么做?
将android:layout_alignBottom="@+id/button_icon"
属性添加到textview
使用LinearLayout并将ImageButton
高度设置为"wrap_content"
,将TextView
设置高度设置为"fill_parent"
。
You will need to make the height of ImageButton
is "wrap_content"
and have the TextView
just "fill_parent"
. 您需要使ImageButton
的高度为"wrap_content"
,并使TextView
只是"fill_parent"
。 You will need to have them both wrapped in a layout parent. 您需要将它们都包装在布局父级中。 That way they are associated with the same layout parent. 这样,它们与相同的布局父级相关联。
Put your elements into LinearLayout, set layout_width="match_parent" and add properties "layout_weight"="1" 将您的元素放入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.