换行内容不适用于相对布局中的垂直线?

Wrap content is not working on Vertical line in Relative Layout?

我正在使用带有背景色的视图在相对布局中创建垂直线。环绕内容不起作用,线条以整个视口为高度。为什么会这样?附上我的无效代码

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f5f5f5"
android:orientation="vertical"
tools:ignore="MissingPrefix">

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <View
        android:layout_width="2dp"
        android:layout_alignParentTop="true"
        android:layout_height="wrap_content"
        android:layout_marginLeft="21.5dp"
        android:background="#a9382b" />

    <TextView
        android:id="@+id/seeall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:textColor="#a9382b"
        android:textSize="11sp"
        tools:text="SEE ALL" />

</RelativeLayout>

</LinearLayout>

在这种情况下将高度设置为 wrap_content 根本行不通。

一般来说,wrap_content 会给视图足够的大小来包含它的所有内容 "inside"(无论是子视图还是只是 TextView 中的文本等),但是您的View 标签没有任何 "inside" 来定义高度。在这种情况下,它将增长以填满所有可用的 space.

如果您希望您的 RelativeLayout 与其中的 TextView 一样高,并且您希望这条线从 的顶部到底部 [=25] =] 大小,请为您的 View 标签使用以下内容:

    <View
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignTop="@+id/seeall"
        android:layout_alignBottom="@+id/seeall"
        android:layout_marginLeft="21.5dp"
        android:background="#a9382b">