问题描述
总之,是有可能告诉孩子在的 RelativeLayout的
的始终匹配的的 RelativeLayout的 其他儿童如何在同一的 RelativeLayout的
的表现?总之,就是这样。下面详细信息。
In short, is it possible to tell a child in a RelativeLayout
to always match the height of that RelativeLayout
regardless of how other children in that same RelativeLayout
behave? In short, that's it. Details below.
我试图做到的,是一个的ListView
行至少有三种观点,以及这些观点一会是怎样的一个条右侧的列表条目(下面红色视图)。我遇到的问题是,有一个的TextView
在左侧,depeding对我的文字有,条纹也不会占满整个布局。这是很清楚地下面的图片说明。
What I'm trying to achieve is a ListView
row with at least three views, and one of those views would be kind of a stripe at the right side of the list entry (the red view below). The problem I'm having is that there is a TextView
at the left side, and depeding on how much text I have, the stripe won't fill the whole layout. This is very clearly explained by images below.
的ListView
项目布局:
ListView
item layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="@+id/bottom_line"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="#fc0" />
<!-- Why match_parent does not work in view below? -->
<View
android:id="@+id/stripe"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="#f00" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/stripe"
android:text="This is a very long line, meant to completely break the match_parent property of the box at right"
style="?android:textAppearanceLarge"/>
</RelativeLayout>
结果:
重复的问题,我想红色条纹总是充满父垂直。您可以看到条纹是不是对准树根的顶部。
Repeating the question, I want the red stripe to always fill the parent vertically. You can see stripe is not aligning to the top of root.
的说明:上面的例子是最简单的,自包含的例子,我能想到的。这只是一个 ListActivity
与匿名 ArrayAdapter
填充由静态字符串
阵列。在的onCreate
相关code最多为8条线,所以不用担心在那里。这是真正的布局。再说,我有这个工作嵌套的LinearLayout
一切已经,但我想减少我的布局结构的深一点,如果可能的话。 的LinearLayout
工作正常,符合市场预期。的
A note: the above example is the simplest, self-contained example I can think of. It's just a ListActivity
with an anonymous ArrayAdapter
populated by a static String
array. The relevant code in onCreate
is at most 8 lines, so no worries there. It's really the layout. Besides, I have this working with nested LinearLayout
s already, but I'm trying to reduce the depth of my layout structure a bit, if possible. LinearLayout
works fine, as expected.
推荐答案
我有同样的要求,我的解决办法是在调整顶部的红色条纹父母的顶部和底部的条纹到文本视图底部左边。在这种情况下,高度变得无关紧要。您可以使用 WRAP_CONTENT
或 match_parent
。
I had same requirement and my solution was to align top of the red stripe to the parent's top, and bottom of the stripe to the bottom of the text view on the left. The height in this case becomes irrelevant. You can either use wrap_content
or match_parent
.
这篇关于match_parent属性在RelativeLayout的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!