Card_view: cardElevation only appears on api <21

I'm currently trying to use the CardView cardElevation attribute. Although height and shadow work fine on KitKat, it does not appear on my Lollipop device. Here is 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> 
+5
source share
2 answers

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

+3
source

This is because the shadow on Lollipop is cropped by the borders of the CardView . You need to add an add-on to RelativeLayout or add android:clipChildren="false" in RelativeLayout .

+2
source

Source: https://habr.com/ru/post/1209757/


All Articles