I am using new ListAdapter, which automatically animates changes. I would like to disable animations or enable/disable it programmatically.
class UserAdapter extends ListAdapter<User, UserViewHolder> { public UserAdapter() { super(User.DIFF_CALLBACK); } @Override public void onBindViewHolder(UserViewHolder holder, int position) { holder.bindTo(getItem(position)); } public static final DiffUtil.ItemCallback<User> DIFF_CALLBACK = new DiffUtil.ItemCallback<User>() { @Override public boolean areItemsTheSame( @NonNull User oldUser, @NonNull User newUser) { // User properties may have changed if reloaded from the DB, but ID is fixed return oldUser.getId() == newUser.getId(); } @Override public boolean areContentsTheSame( @NonNull User oldUser, @NonNull User newUser) { // NOTE: if you use equals, your object must properly override Object#equals() // Incorrectly returning false here will result in too many animations. return oldUser.equals(newUser); } } }
Open Settings . Scroll down and select Accessibility. Scroll down to Display and tap Text and display. Tap the toggle switch for Remove animations to turn it on.
In macOS: System Preferences > Accessibility > Display > Reduce motion. In iOS: Settings > General > Accessibility > Reduce Motion. In Android 9+: Settings > Accessibility > Remove animations.
Another solution is to simply remove the item animator altogether.
recyclerView.itemAnimator = null
You could try to disable or enable animations with setSupportsChangeAnimations
on RecyclerView
item animator:
SimpleItemAnimator itemAnimator = (SimpleItemAnimator) recyclerView.getItemAnimator(); itemAnimator.setSupportsChangeAnimations(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With