android - 在父级中居中嵌套相对布局
问题描述
我必须为空屏幕制作(某种)页脚。我的父布局是RelativeLayout1
. 在这个布局里面我有ToolBar
,下面是另一个RelativeLayout2
.
这里面RelativeLayout2
是 Button 和另一个RelativeLayout3
. 我是这样做的,因为我想将RelativeLayout3
内容居中RelativeLayout2
并且Button
应该始终对齐父布局的底部(RelativeLayout2
)
我之前得到了类似问题的答案,但它并不总是有效。我现在的问题是RelativeLayout3
垂直偏离中心(它更接近底部)。
它应该是什么样子
它实际上看起来如何
如何解决这个问题?
完整布局:
<?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>
解决方案
如果我理解正确,您应该将以下内容添加到您的order_complete_image_text_layout
.
android:layout_above="@id/order_complete_continue_button"
推荐阅读
- r - 基于 R 中条件的新列
- python - 是否可以在没有循环的情况下找到矩阵中的行之间的相似性?
- html - 使用python抓取ajax页面,但在请求几次后它返回假值
- android - 使用 GitHub Actions 部署到 Play 商店时无法读取未定义的属性“替换”
- r - dplyr 函数需要 dplyr:: 前缀时出错,即使在加载包时也是如此
- c# - 统一的动画速度
- javascript - API 是携带数据还是只是由其他东西携带的数据?
- sql - Whitelabel 错误页面出现意外错误(类型=内部服务器错误,状态=500)。空标识符
- php - 在 aws ubuntu 上安装期间,mautic 抛出错误 php 错误
- javascript - jQuery Google Translate 403 翻译调用错误