Android CardView shadow gets cut off
Asked Answered
T

2

5

Shadows seem to cut off on some of my CardView usages. Any idea why? looks like removing the padding on the parent resolves the issue, but I do want the padding. And I don't want to use margin on the inner card, because there are other views aligned and I prefer having the padding set on the parent to apply to all children

Any solutions?

layout

<?xml version="1.0" encoding="utf-8"?>

<androidx.cardview.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/standard_spacing"
    android:layout_marginLeft="@dimen/standard_spacing"
    android:layout_marginRight="@dimen/standard_spacing"
    android:layout_marginBottom="@dimen/smaller_spacing"
    app:cardCornerRadius="@dimen/standard_card_corner_radius"
    app:cardElevation="10dp">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="@dimen/standard_spacing">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:cardBackgroundColor="@color/light_gray_background"
            android:minHeight="40dp"
            app:cardElevation="5dp"
            app:cardCornerRadius="@dimen/standard_card_corner_radius" >

        </androidx.cardview.widget.CardView>

    </androidx.appcompat.widget.LinearLayoutCompat>

</androidx.cardview.widget.CardView>

enter image description here

Tunnage answered 26/3, 2021 at 0:26 Comment(0)
E
8

add

android:clipToPadding="false"

to LinearLayout

Exorcism answered 26/3, 2021 at 4:43 Comment(0)
W
5

Here is how you can solve it

add to CardView or MaterialCardView

app:cardUseCompatPadding="true"
Wellspoken answered 17/11, 2023 at 2:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.