Andrew Orobator
Andrew Orobator

Reputation: 8666

card_view:cardElevation only appears on api < 21

I'm currently trying to use the CardView's cardElevation attribute. While the elevation and shadow works perfectly on KitKat, it does not appear on my Lollipop device. Here's my XML:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="72dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="2dp"
        card_view:cardUseCompatPadding="true">

        <!--Stuff on card view-->


    </android.support.v7.widget.CardView>
</RelativeLayout>

Upvotes: 5

Views: 6307

Answers (2)

yigit
yigit

Reputation: 38273

You can set cardUseCompatPadding to true to enforce CardView to add inner padding for shadows in L.

Upvotes: 3

pdegand59
pdegand59

Reputation: 13039

This is happening because the shadow on Lollipop is clipped by bounds of the CardView. You need to add some padding to the RelativeLayout or add android:clipChildren="false" to the RelativeLayout.

Upvotes: 2

Related Questions