Saturday 20 March 2021

RecyclerView Initial animation not working when scroll to a specific position

I create a RecyclerView that has a started animation on it. So, when the recyclerView is populated the first element "falls" from the top of the screens

RecyclerView

 <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layoutAnimation="@anim/layout_animation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

Layout Animation

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/item_animation_fall_down"
    android:animationOrder="normal"
    android:delay="15%" />

Animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600">

    <translate
        android:fromYDelta="-50%"
        android:toYDelta="0"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

    <scale
        android:fromXScale="105%"
        android:fromYScale="105%"
        android:toXScale="100%"
        android:toYScale="100%"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

</set>

Its works fine if the screen opens with the first element selected. But sometimes I need to focus on a specific item in a different position of the recyclerView.

I Do that with this code:

recyclerView.scrollToPosition(args.selectedIndex)

Is there a way to force the animation to happens on that scenario!?



from RecyclerView Initial animation not working when scroll to a specific position

No comments:

Post a Comment