4

I have an app that uses CardViews very extensively, pretty much for every UI element in each view. I noticed that the shadow around each CardView is much thicker around views close to the bottom than it is around views closer to the top:

example

Any idea why that is, and if there's a way to change that behavior?

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
Nir Arbel
  • 215
  • 1
  • 3
  • 11

2 Answers2

2

That is so because that is what Material Design was mean to represent.

CardView appears to be thick at the bottom as that represents the shadow which a real card will cast if the cardView was replaced by it.

If you want to tweak this parameter, you'll need to adjust the android:elevation="2dp" attribute for the cardView.

Setting it to 0dp will disable the shadow and increasing it will increase it.

If you want to have shadows all around the cardView, refer to this answer which explains how to achieve it.

Community
  • 1
  • 1
harshithdwivedi
  • 1,411
  • 16
  • 37
  • Thanks, sorry, I didn't word my question correctly. More info in my response to Sergey, but as you say I don't think what I want is doable using card view elevation. – Nir Arbel Jan 24 '17 at 20:44
  • @NirArbel you can view this answer to display an even shadow across your card view. http://stackoverflow.com/a/36779481/5471095 – harshithdwivedi Jan 25 '17 at 14:29
  • @the-dagger he's saying cardviews displayed lower on the screen have thicker shadows than those at the top of the screen. i'm seeing this behavior as well. –  Nov 18 '18 at 00:37
0

It's a normal behavior of android:elevation

If you want to have the same thick for top and bottom, use own background.

For example, you can use nine patch image. Shadow generator: http://inloop.github.io/shadow4android/

  • Sorry, my question was poorly phrased. I meant that shadows around views close to the bottom is thicker than that around the views close to the top. I edited my question to reflect that. I was hoping to avoid using a background, but it sounds like I may have to if I want an even shadow. Thanks! – Nir Arbel Jan 24 '17 at 20:42