Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable animation on notifyItemRangeInserted()

I'm using a RecyclerView. After adding items to the RecyclerView, I need to call:

notifyItemRangeInserted(int positionStart, int itemCount); 

However, this shows a sort of "slide down" animation. Is there a way that I can disable this animation?

Thanks.

like image 423
d84619 Avatar asked Jun 01 '17 00:06

d84619


People also ask

How do I turn off screen animation?

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.

How do I turn off animation remover?

To access the Accessibility features on your Android device open the Settings app . In the Settings app, select Accessibility from the list. Now scroll down to the Display section and select Remove Animations to set the toggle switch to On.


2 Answers

try clearing the RecyclerView item animator

recyclerView.setItemAnimator(null); 

you can re-enable your animation after if needed.

recyclerView.setItemAnimator(null); notifyItemRangeInserted(int positionStart, int itemCount); recyclerView.setItemAnimator(new DefaultItemAnimator()); 
like image 120
Matthew Shearer Avatar answered Oct 04 '22 08:10

Matthew Shearer


You can also do it with Data Binding in your xml layout file like this:

<androidx.recyclerview.widget.RecyclerView     android:id="@+id/my_recycler_view"     android:layout_width="match_parent"     android:layout_height="wrap_content"     app:itemAnimator="@{null}" /> 

This is possible simply because RecyclerView has a public function called setItemAnimator!

like image 42
Chrisser000 Avatar answered Oct 04 '22 09:10

Chrisser000