Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 916
Andrew Orobator Avatar asked Dec 23 '14 08:12

Andrew Orobator


2 Answers

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

like image 51
yigit Avatar answered Sep 30 '22 06:09

yigit


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.

like image 44
pdegand59 Avatar answered Sep 30 '22 06:09

pdegand59