Philip Kahn
Philip Kahn

Reputation: 713

cardElevation not showing shadows on Lollipop

I've checked a whole bunch of answers here, and still no dice. Android Studio preview shows the shadow, but not the 5.1.1 Nexus 7.

Here's my XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:card_view="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  card_view:cardCornerRadius="4dp"
  card_view:cardUseCompatPadding="true"
  card_view:cardElevation="20sp"
  card_view:cardPreventCornerOverlap="true"
  android:layout_margin="6dp"
>

So I've used cardUseCompatPadding (also here), checked the documentation, made sure the card has a margin .... no dice.

I posted the total XML file over at https://gist.github.com/tigerhawkvok/0ca3d1f402afa29642d5 .

Help?

Upvotes: 0

Views: 1817

Answers (1)

Deepanshu
Deepanshu

Reputation: 826

On device, shadows are drawn only if the view background is not null and not transparent. However, a bug in the layout preview in Android Studio prevents it from checking the background before drawing the shadow. Hence you see the difference.

But you shouldn't really need to set the elevation on card view, since it creates its own shadow or sets the elevation depending on the platform version.

Upvotes: 1

Related Questions