1

I stumbled upon something weird. I am using the same CardView component in more than one place in my app, all with the same elevation (3dp), and they all looks the same. However, for one scenario I need to embed the CardView inside a ScrollView. I didn't change anything in the CardView configuration, but the shadow now looks different.

This is my layout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:padding="16dp"
            android:scrollbars="none">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipChildren="false"
        android:clipToPadding="false"
        app:cardCornerRadius="8dp"
        app:cardElevation="3dp"
        app:cardUseCompatPadding="true">

        <!-- some other views-->

     </androidx.cardview.widget.CardView>
</ScrollView>

In the picture below you can see on the right the CardView and on the left the two shadows: on the top the shadow generated by the CardView alone, on the bottom the one generated when the CardView is inside a ScrollView. As you can see the second one appears darker and thicker.

NOTE: The background color (#FAFAFA) is the same in both scenario.

enter image description here

GVillani82
  • 17,196
  • 30
  • 105
  • 172

1 Answers1

0

For both cases, I would check the following properties as it could contribute to the difference you're seeing:

  • getTranslationZ()
  • getElevation()
  • getOutlineAmbientShadowColor() (this is only valid in API 28+)
  • getOutlineSpotShadowColor() (this is only valid in API 28+)

Plus, checking Layout inspector to see if there's any view that could affect to the rendering.

Also, this article from Sebastiano Poggi could be of help.

Xavier Rubio Jansana
  • 6,388
  • 1
  • 27
  • 50
  • The values are the same for both scenario. Except the last two cause I am using API 26 device. – GVillani82 Mar 25 '19 at 14:03
  • Could you check it in a 28+ device (or emulator) and check if it changes anything and if the values for the Outline*ShadowColor properties are the same. From what I know those properties already existed before (I guess from 21), is only that they where not accessible (easily?). – Xavier Rubio Jansana Mar 25 '19 at 14:33