相对布局:layout_below 一个 CenterVertical 元素

Relative layout: layout_below a CenterVertical element

当我想在具有属性

的元素下方制作按钮时,我遇到了问题
android:layout_centerVertical="true"

文本视图垂直居中,按钮应在其下方 但事实并非如此

我的 XML 片段看起来像:

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray">

        <ImageView
            android:id="@+id/headerImage"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop"/>

        <View
            android:layout_width="match_parent"
            android:background="@color/ecommerce1Foreground"
            android:layout_height="200dp"/>

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:layout_centerVertical="true"
            android:gravity="center_horizontal"
            android:text="ZARA WOMEN DRESS"
            android:textColor="@android:color/white"
            android:textSize="18sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/buttonShopNow"
            style="@style/ButtonYellow"
            android:layout_width="wrap_content"
            android:layout_height="32dp"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/title"
            android:layout_marginTop="8dp"
            android:text="SHOP NOW"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

    </RelativeLayout>

首先是你 如果你的身高是固定的。将其交给 Parent,即使您的相对布局高度为 200dp。之后,您必须在 Button

中使用 @+id/title