MaterialCardView 被 children 覆盖时阴影不一致

Inconsistent shadow on MaterialCardView when its overlaid by children

当 MaterialCardView 的 child 完全覆盖它时,它下面的阴影消失。我已经尝试将高度设置为视图本身但没有效果。

布局示例:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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=".MainActivity">

    <!-- Elevation of this card is large for demonstration purposes -->
    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:layout_margin="16dp"
        app:cardElevation="24dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <View
            android:layout_width="120dp"
            android:layout_height="match_parent"
            android:background="@color/purple_500"
            android:elevation="24dp"
            app:elevation="24dp" />
    </com.google.android.material.card.MaterialCardView>

</androidx.constraintlayout.widget.ConstraintLayout>

问题截图:

这里的阴影在卡片的白色背景下清晰可见,但在紫色视图下不可见。

该应用已在 API 30 模拟器上进行了测试,但我在 API 29 物理设备上观察到了类似的行为。

好吧,事实证明这只是一种错觉:如果你在 Paint 中覆盖紫色控件,阴影是一致的:

现在由我来决定如何防止以下错觉影响我的应用程序的视觉体验。