【问题标题】:Relative layout: layout_below a CenterVertical element相对布局:layout_below 一个 CenterVertical 元素
【发布时间】:2018-09-18 02:07:54
【问题描述】:

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

android:layout_centerVertical="true"

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

我的 XML sn-p 看起来像:

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

【问题讨论】:

    标签: android alignment android-relativelayout


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 2013-08-29
      • 2012-09-17
      • 2018-03-23
      • 1970-01-01
      • 2018-05-21
      相关资源
      最近更新 更多