Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange shadow behavior during `alpha` animation

Have recycler with CardView items. When screen open - I start alpha animation on recycler :

recyclerView.animate().alpha(1f).setStartDelay(300).start()

Recycler item:

<android.support.v7.widget.CardView
    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="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginTop="6dp"
    android:layout_marginEnd="20dp"
    android:layout_marginBottom="6dp"
    app:cardCornerRadius="10dp"
    app:cardElevation="4dp">
...
</android.support.v7.widget.CardView>

Problem that while this animation running the shadow of CardView directed to the up but when animation ends shadow change direction to the bottom (as normal)

Problem was found only on Android 9.

P.S. sorry for my english)

like image 328
Ivan Krasilnikov Avatar asked Feb 12 '19 09:02

Ivan Krasilnikov


2 Answers

Found a workaround. Make sure the alpha-animation targets on CardView itself instead of its parent and its parent's alpha must be 1F. This work in my case. Hope it can help you too.

like image 95
Shawlaw Avatar answered Nov 20 '22 01:11

Shawlaw


I have found a partial fix,

If you add android:layerType="hardware" to the parent view the shadow no longer flips direction.

The down side is the shadow permanently points in the wrong direction.

like image 1
user3079669 Avatar answered Nov 20 '22 01:11

user3079669