简体   繁体   English

海拔没有在cardview上正确显示

[英]Elevation no showing properly on cardview

I have the below xml我有以下 xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data></data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/mainHolder_CL"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/preview_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        app:srcCompat="@color/mcorner_page_background" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/title"
        style="@style/HomeScreenTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:text="@string/screen_title_corners"
        app:addWindowInsetMarginTop="@{true}"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.cardview.widget.CardView
        android:id="@+id/cornerPeace"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="30dp"
        android:layout_marginTop="35dp"
        android:layout_marginEnd="30dp"
        android:layout_marginBottom="30dp"
        android:background="@android:color/white"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        app:layout_constraintBottom_toTopOf="@+id/otherCorners"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/title">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="15dp">

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/peaceImg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_bottom_nav_home_new" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/header"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="header"
                android:textColor="@android:color/black"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/peaceImg" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/desc"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="10dp"
                android:text="description"
                app:layout_constraintBottom_toTopOf="@+id/separator"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/header" />

            <View
                android:id="@+id/separator"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginBottom="5dp"
                android:alpha="0.1"
                android:background="@android:color/black"
                app:layout_constraintBottom_toTopOf="@+id/mins"
                app:layout_constraintEnd_toEndOf="@+id/desc"
                app:layout_constraintStart_toStartOf="@+id/desc" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/mins"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="minutes"
                android:textColor="@android:color/black"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/otherCorners"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp"
        android:layout_marginBottom="20dp"
        app:addBottomNavigationHeightMarginBottom="@{true}"
        app:addWindowInsetMarginBottom="@{true}"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <androidx.cardview.widget.CardView
            android:id="@+id/corner1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            app:cardElevation="10dp"
            app:cardCornerRadius="10dp"
            app:layout_constraintEnd_toStartOf="@+id/corner2"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp">

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/challengeImg"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_bottom_nav_home_new" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/challengesTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:text="corner 1"
                    android:textSize="13sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/challengeImg" />

            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/corner2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="15dp"
            android:layout_marginEnd="15dp"
            android:background="@android:color/white"
            android:clipToPadding="false"
            app:cardElevation="10dp"
            app:cardCornerRadius="10dp"
            app:layout_constraintEnd_toStartOf="@+id/corner3"
            app:layout_constraintStart_toEndOf="@+id/corner1"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp">

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/humourImg"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_bottom_nav_home_new" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:text="corner 2"
                    android:textSize="13sp"
                    app:fontFamily="@font/font_regular"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/humourImg" />

            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/corner3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:clipToPadding="false"
            app:cardElevation="10dp"
            app:cardCornerRadius="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/corner2"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp">

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/thoughtImg"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_bottom_nav_home_new" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:text="corner 3"
                    android:textSize="13sp"
                    app:fontFamily="@font/font_regular"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/thoughtImg" />

            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

This is the output I get这是我得到的 output 在此处输入图像描述

As you see I applied the elevation to corner 1,2 and 3 but it isn't showing properly.如您所见,我将高程应用到角 1,2 和 3,但它没有正确显示。 It seems to be getting cut-off.好像要断了What am I missing here?我在这里想念什么?

I'd debug the "otherCorners" ConstraintLayout.我会调试“otherCorners”约束布局。

You seem to have set the margins of that layout in a way to make it equal to the big CardView above it.您似乎已经将该布局的边距设置为使其等于其上方的大 CardView 。 And since the first and last CardView inside the otherCorners Layout are placed directly against the borders of the parent it prob just cuts off the shadow of the elevation on the sides.而且由于 otherCorners 布局中的第一个和最后一个 CardView 直接放置在父级的边界上,因此它可能只是切断了侧面高程的阴影。 Same story, different values, for the bottom.同样的故事,不同的价值观,对于底层。

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

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