在父项中将嵌套相对相对布局居中

时间:2018-08-31 11:33:40

标签: android android-layout kotlin

我必须为空白屏幕创建(某种)页脚。我的父级布局为RelativeLayout1。在此布局中,我有ToolBar,下面是另一个RelativeLayout2

RelativeLayout2内是Button,另一个RelativeLayout3。之所以这样,是因为我想将RelativeLayout3中的RelativeLayout2内容居中,并且Button应该始终与父布局的底部对齐(RelativeLayout2

我之前也有类似问题的答案,但这并不总是有效。我现在的问题是RelativeLayout3在垂直方向上偏离中心(靠近底部)。

外观如何

How it should looks like

实际外观

How it actually looks like

该如何解决?

完整版式:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/colorBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/toolbar_round"
        android:orientation="horizontal">

        <include
            android:id="@+id/toolBarContent"
            layout="@layout/order_toolbar_layout" />

    </android.support.v7.widget.Toolbar>

    <RelativeLayout
        android:id="@+id/order_complete_footer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolBar"
        android:gravity="center"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/order_complete_image_text_layout"
            android:layout_centerInParent="true"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/order_complete_image"
                android:layout_width="175dp"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginEnd="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:src="@drawable/footer_image" />

            <TextView
                android:id="@+id/order_complete_text1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/order_complete_image"
                android:layout_marginEnd="50dp"
                android:layout_marginStart="50dp"
                android:layout_marginTop="-12dp"
                android:gravity="center_horizontal"
                android:text="@string/order_complete_screen_text1"
                android:textColor="@color/colorItemMinor"
                android:textStyle="bold"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/order_complete_text2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/order_complete_text1"
                android:layout_marginEnd="50dp"
                android:layout_marginStart="50dp"
                android:gravity="center_horizontal"
                android:text="@string/order_complete_screen_text2"
                android:textColor="@color/colorItemMinor"
                android:textSize="12sp" />
        </RelativeLayout>

        <Button
            android:id="@+id/order_complete_continue_button"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/address_creation_button_padding_TOP_BOTTOM"
            android:layout_marginEnd="@dimen/address_creation_button_padding_START_END"
            android:layout_marginStart="@dimen/address_creation_button_padding_START_END"
            android:layout_marginTop="@dimen/address_creation_button_padding_TOP_BOTTOM"
            android:background="@drawable/login_button_background_void"
            android:text="@string/order_complete_screen_button_label"
            android:textAppearance="@style/VoidLoginButtonTextAppearance" />

    </RelativeLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:-1)

如果我理解正确,则应将以下内容添加到order_complete_image_text_layout中。

android:layout_above="@id/order_complete_continue_button" 

@JanStoltman