Reputation: 1054
I am a beginner in Android Development. When I search for RecyclerView animation, I have found about RecyclerView.ItemAnimator and but I can't find any tutorial on how to use this. I have read this How to use ItemAnimator in a RecyclerView?. But still, I don't get anything.
I have found documentation.
By default, RecyclerView uses DefaultItemAnimator.
What type of animation can expect from DefaultItemAnimator If I use RecyclerView?
I have used LayoutAnimation, When should I use RecyclerView.ItemAnimator?
Upvotes: 2
Views: 4144
Reputation: 2966
You can use Any type of animation to animate your recycler view item
Required steps to build the following behavior
Start off by creating the file item_animation_fall_down.xml
in res/anim/
and add the following:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@integer/anim_duration_medium">
<translate
android:fromYDelta="-20%"
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>
Defining the LayoutAnimation
With the item animation done it’s time to define the layout animation which will apply the item animation to each child in the layout. Create a new file called layout_animation_fall_down.xml
in res/anim/
and add the following:
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/item_animation_fall_down"
android:delay="15%"
android:animationOrder="normal"
/>
A LayoutAnimation can be applied both programmatically and in XML.
JAVA
int resId = R.anim.layout_animation_fall_down;
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(ctx, resId);
recyclerview.setLayoutAnimation(animation);
XML
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutAnimation="@anim/layout_animation_fall_down"
/>
For more info visit here
Upvotes: 2
Reputation: 1793
You wish to animate rows of recyclerview. Use below function
public void setFadeAnimation(View view) {
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(1000);
view.startAnimation(anim);
}
Now Go to Adapter class and call this function like this inside onBindViewHolder method
setFadeAnimation(myViewHolder.itemView);
It will animate your rows
Upvotes: 0