0

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?

Community
  • 1
  • 1
Philip Kahn
  • 614
  • 1
  • 5
  • 22
  • what if you change 20sp to 5dp ? – Jemshit Apr 07 '15 at 19:34
  • @JCodex , no dice - http://imgur.com/LJEcsX9 – Philip Kahn Apr 07 '15 at 19:51
  • do you want to put shadow on cardview in list (which you already have shadow) or to View on top(Scribner bend title) ? – Jemshit Apr 07 '15 at 19:53
  • @JCodex the pop up dialog is supposed to be a bigger version of that smaller card with more detail, so, the View on top (eg, it's supposed to "float" on top of the other card list) – Philip Kahn Apr 07 '15 at 19:56
  • I dont advice you to use card view for dialogs, which is not suggested in material design. Use AlertDialog with custom view which looks like cardview. You may want to check this dialog library: https://github.com/afollestad/material-dialogs – Jemshit Apr 07 '15 at 20:01
  • @JCodex It's not really a dialog, nor is the content really particularly suited to the strict-Material/Polymer look (in that instance -- there are others where your library will be very helpful). If it's an intractable problem I'll just throw a background behind it, but I'd rather have it shadowed. – Philip Kahn Apr 07 '15 at 20:10
  • How are you making card bigger? Are you replaceing it inside `ListView`/`RecyclerView`? I think the problem is way you are trying to display this card. – paulina_glab Apr 07 '15 at 20:33
  • @onka I'm just drawing a new popupWindow on the screen: `View popupView = layoutInflater.inflate(R.layout.expanded_view, null); popupView.setAnimation(AnimationUtils.loadAnimation(refActivity.getApplicationContext(), R.anim.fadein)); final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);` – Philip Kahn Apr 07 '15 at 21:48

1 Answers1

1

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.

Deepanshu
  • 806
  • 6
  • 6