When a child of a MaterialCardView fully overlays it, the shadow under it disappears. I have tried setting elevation to the view itself but to no effect.
Example layout:
<?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>
Screenshot of the problem:
Here shadow is clearly visible under white background of the card, but not under purple view.
The app was tested on API 30 emulator, but I have observed similar behaviour on API 29 physical device.
question from:
https://stackoverflow.com/questions/65642209/inconsistent-shadow-on-materialcardview-when-its-overlaid-by-children 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…