gpt4 book ai didi

android - RelativeLayout 中子级的 match_parent 属性

转载 作者:IT老高 更新时间:2023-10-28 22:12:33 25 4
gpt4 key购买 nike

简而言之,是否可以告诉 RelativeLayout 中的 child 始终匹配该 RelativeLayout 的高度> 不管同一个 RelativeLayout 中的其他 child 的行为如何? 简而言之,就是这样。详情如下。

我想要实现的是一个具有至少三个 View 的 ListView 行,其中一个 View 将是列表条目右侧的条纹(红色 View 以下)。我遇到的问题是左侧有一个 TextView ,并且取决于我有多少文本,条纹不会填满整个布局。下面的图片非常清楚地解释了这一点。

ListView 项目布局:

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

结果:

RelativeLayout with child not filling the whole layout vertically

将 strip 和根高度设置为 match_parent 没有区别。我做到了。

重复这个问题,我希望红色条纹始终垂直填充父级。您可以看到条纹未与根顶部对齐。

注意:上面的例子是我能想到的最简单、独立的例子。它只是一个 ListActivity 和一个由静态 String 数组填充的匿名 ArrayAdapteronCreate中的相关代码最多8行,不用担心。这真的是布局。此外,我已经在使用嵌套的 LinearLayout 了,但如果可能的话,我正在尝试减少布局结构的深度。 LinearLayout 工作正常,正如预期的那样。

最佳答案

我有同样的要求,我的解决方案是将红色条纹的顶部与父级的顶部对齐,并将条纹的底部与左侧 TextView 的底部对齐。在这种情况下,高度变得无关紧要。您可以使用 wrap_contentmatch_parent

关于android - RelativeLayout 中子级的 match_parent 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18303410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com