繁体   English   中英

相对布局:位于CenterVertical元素下方的layout_below

[英]Relative layout: layout_below a CenterVertical element

我要在具有属性的元素下方制作按钮时遇到问题

android:layout_centerVertical="true"

textview垂直居中,按钮应位于其下方,但事实并非如此

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

首先是你,如果你有固定的身高。 给它的父母,即使您的相对布局高度为200dp。 之后,您必须在Button中使用@ + id / title

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM