android - 将两个 ConstraintLayout 带到 Button 前面

标签 android android-constraintlayout z-order

我正在尝试在 Android 上实现以下设计。

Android Screen

我知道要在那个位置放置按钮,我应该有两个约束布局;一种用于整个更改密码表单,另一种用于不带保存按钮的更改密码表单,然后将保存按钮的 TopBottom 约束设置为第二个 ConstraintLayout。
但是当我这样做时,按钮位于表单的后面,这就是问题所在:

enter image description here

这是我的 XML:

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ChangePasswordActivity">
    
        <include
            android:id="@+id/changePasswordBar"
            layout="@layout/top_bar_full"></include>
    
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <android.support.constraint.ConstraintLayout
                android:id="@+id/changePasswordCTL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activities_constraint_top_bottom"
                android:layout_marginEnd="@dimen/activities_constraint_start_end"
                android:layout_marginStart="@dimen/activities_constraint_start_end"
                android:layout_marginTop="@dimen/activities_constraint_top_bottom"
                android:background="@drawable/radius_background_exchange"
                android:elevation="5dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">
    
                // some EditText and TextView views here
    
    
            </android.support.constraint.ConstraintLayout>

    <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
                android:id="@+id/changePasswordBT"
                style="@style/customButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="32dp"
                android:layout_marginStart="32dp"
                android:layout_marginTop="8dp"
                android:fontFamily="@font/sans_web_medium"
                android:text="@string/finish"
                android:textAllCaps="false"
                android:textColor="@android:color/white"
                android:textSize="@dimen/signinup_button_font_size"
                app:initialCornerAngle="5dp"
                app:layout_constraintBottom_toBottomOf="@+id/changePasswordCTL"
                app:layout_constraintEnd_toEndOf="@+id/changePasswordCTL"
                app:layout_constraintStart_toStartOf="@+id/changePasswordCTL"
                app:layout_constraintTop_toBottomOf="@+id/changePasswordCTL"
                app:spinning_bar_color="@android:color/white"
                app:spinning_bar_padding="6dp"
                app:spinning_bar_width="4dp" />
    
        </android.support.constraint.ConstraintLayout>
    
    </android.support.design.widget.CoordinatorLayout>

最佳答案

elevation 不在图片中时,稍后在 XML 文件中定义的 View 将绘制在先前定义的 View 的“顶部”。但是,您的密码表单有 android:elevation="5dp",这将覆盖正常的绘图顺序。

要修复,还要为按钮添加高度。 android:elevation="5dp" 应该足够了,因为那时它们处于相同的高度并且应该适用正常规则。但是你可以给它更高的高度,以保证它总是在密码表单的顶部绘制。

关于android - 将两个 ConstraintLayout 带到 Button 前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53344413/

相关文章:

android - 手机间隙 : how to use Google Analytics without plugin

java - 使用sqlite登录失败

android - 如何以编程方式在约束布局中添加左右边距

iphone - ios 6上的导航栏与其他 View 重叠

forms - 类似于 TApplication 的 SendToBack

android - DataChannel.state() 总是返回 CONNECTING webRTC Android

Android:我如何做 'Matrix.mapPoints(float[] points)' 的相反操作?

android - 尝试使用 ConstraintLayout 复制 GridLayout 列对齐

android - View 之间的间距相等,其中一些在 ConstraintLayout 上使用父级的百分比

android - 如何在 android 中更改 surfaceview 的 z 顺序运行时