Disable / pause RecyclerView animation and / or just allow RecyclerView animation on scrolling

So, basically I have a simple RecyclerView.Adapter and I have something like this:

public void onBindViewHolder(ViewHolder viewHolder, int position) {
    final Session currentSession = sessionList.get(position);

    viewHolder.textTittle.setText(currentSession.getTitle());
    viewHolder.textStartEnd.setText(currentSession.getStartHour() + " - " + currentSession.getEndHour());
    viewHolder.textDate.setText(currentSession.getDateFormatedString());
    viewHolder.textTrack.setText(currentSession.getTrack());
    viewHolder.textRoom.setText(currentSession.getRoom());


    if (position > this.lastPosition) {
        animate(viewHolder, true);
    } else {
        animate(viewHolder, false);
    }

    this.lastPosition = position;
    viewHolder.setClickListener(clickListener, currentSession);
}

      

The animations are fine when scrolling up / down, but when I change all the data or even load the RecyclerView (contains a CardView list) the animations seem very confusing. I was trying to temporarily turn off the animation when I change all the data or just turn it on when I'm viewing the CardView list.

Do you have any idea how to do this?

Thank.

+3


source to share


1 answer


The RecyclerView has built-in animation support, but does not yet support scroll animation.

It looks like you're animating them yourself, in this case (if you don't want to add / remove / change animations) just set the ItemAnimator to null. ( RecyclerView#setItemAnimator

).



These custom animations that you add will cause problems when reworking, so you should implement as well onFailedToRecycle

. https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#onFailedToRecycleView(VH)

+5


source







All Articles