In my project I need disable the \"change\" animation of RecyclerView
while notifyItemChanged
.
I investigated in the source of Recycl
Nothing of the above solutions worked for me. What worked was using the TransitionManager and setting the scene transition to null
TransitionManager.go(new Scene(recyclerView), null);
To re-enable the default animation you can create a new AutoTransition and set it to the same method above:
AutoTransition autoTransition = new AutoTransition();
TransitionManager.go(new Scene(recyclerView), autoTransition);
I've created an Extention Class, to disable animation
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
fun RecyclerView.disableAnimation() {
(itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
}
You can call it like this:
recyclerView.disableAnimation()
If found a solution, for everyone who wants to keep all the animations given by the DefaultItemAnimator, but getting rid of the "blink" animation that occurs every time the view is updated.
First, get the source code of DefaultItemAnimator. Create a class with the same name in your project.
Second, set the ItemAnimator to a new instance of your modified DefaultItemAnimator, like so:
recyclerView.setItemAnimator(new MyItemAnimator());
Then, go in the new classes source code and locate the method
animateChangeImpl(final ChangeInfo changeInfo) { ... }
Now, we simply have to locate the method calls changing alpha values. Find the following two lines and remove the .alpha(0) and .alpha(1)
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { ... }
newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1).setListener(new VpaListenerAdapter() { ... }
like so
oldViewAnim.setListener(new VpaListenerAdapter() { ... }
newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).setListener(new VpaListenerAdapter() { ... }
I had the same problem. When calling notifyItemChanged there was a red overlay flashing. After experimenting around with your code I finally removed the default Animator by simply calling
recyclerView.setItemAnimator(null);
on the RecyclerView.
Just if someone stumbles like me:
Somehow setSupportsChangeAnimations(false)
didn't work for me, but recyclerView.getItemAnimator().setChangeDuration(0)
has just removed the animation nicely.
The easiest solution is to extend DefaultItemAnimator
and set setSupportsChangeAnimations
to false
right in the constructor:
public class DefaultItemAnimatorNoChange extends DefaultItemAnimator {
public DefaultItemAnimatorNoChange() {
setSupportsChangeAnimations(false);
}
}