1

I'm wondering why each card in my recyclerview has more shadow than the card before. Is this normal behaviour? if not, what causes this and how can i avoid it?

I can't find any information on this anywhere outside of an old stackoverflow post (Elevated RecyclerView items get progressively deformed (elevation changes))

The list item layout

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="280dp"
android:layout_height="180dp"
app:cardCornerRadius="20dp"
app:cardUseCompatPadding="true"
app:cardElevation="6dp">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>

enter image description here

jps
  • 20,041
  • 15
  • 75
  • 79
DennisVA
  • 2,068
  • 1
  • 25
  • 35

2 Answers2

0

there are two light sources in Android - "ambient" (general, "flat") and "key" (wirtually located at some point in space). HERE you will find some doc/description. First one gives you equal shadow around card. Second one gives "more" shadow at the opposite edge that "key" light is placed

"key" light is placed on top of the screen. Lets imagine that status bar is "key" light:

  • card on top of list is very near status bar, almost under it, so it have small "bottom" shadow, as a man have smaller shadow standing in the field at the midday
  • card on the bottom of screen is far from status bar, so its shadow is longer, just like shadows on sunset

some more info in this SO

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Thanks for your response. I have read these things already; in the paragraph "light sources" they say that ' shadows occur when light sources are blocked by Material surfaces at various positions along the z-axis' – DennisVA Oct 14 '21 at 11:24
  • I'm pretty shure that I've seen some animations with these lights in official doc, but now I've tried to find that page and failed, sorry... – snachmsm Oct 14 '21 at 11:27
0

I found a blog that explains this more: https://blog.sebastiano.dev/playing-with-elevation-in-android/

So this basically confirms that this is normal behaviour

DennisVA
  • 2,068
  • 1
  • 25
  • 35