wasabeef/recyclerview-animators


An Android Animation library which easily add itemanimator to RecyclerView items.

License: Apache-2.0

Language: Java

Keywords: android, android-library, animation, java, kotlin, recyclerview


RecyclerView Animators

Gitter

Android Arsenal License Download

RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations.

Please feel free to use this.

Features

  • Animate addition and removal of ItemAnimator
  • Appearance animations for items in RecyclerView.Adapter

Demo

ItemAnimator

Adapters

Samples

How do I use it?

Setup

Gradle

dependencies {
  // jCenter
  compile 'jp.wasabeef:recyclerview-animators:2.2.6'
}

ItemAnimator

Step 1

Set RecyclerView ItemAnimator.

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setItemAnimator(new SlideInLeftAnimator());
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
SlideInUpAnimator animator = new SlideInUpAnimator(new OvershootInterpolator(1f));
recyclerView.setItemAnimator(animator);

Step 2

Please use the following
notifyItemChanged(int)
notifyItemInserted(int)
notifyItemRemoved(int)
notifyItemRangeChanged(int, int)
notifyItemRangeInserted(int, int)
notifyItemRangeRemoved(int, int)

If you want your animations to work, do not rely on calling notifyDataSetChanged(); as it is the RecyclerView's default behavior, animations are not triggered to start inside this method.

public void remove(int position) {
  mDataSet.remove(position);
  notifyItemRemoved(position);
}

public void add(String text, int position) {
  mDataSet.add(position, text);
  notifyItemInserted(position);
}

Advanced Step 3

You can change the durations.

recyclerView.getItemAnimator().setAddDuration(1000);
recyclerView.getItemAnimator().setRemoveDuration(1000);
recyclerView.getItemAnimator().setMoveDuration(1000);
recyclerView.getItemAnimator().setChangeDuration(1000);

Advanced Step 4

Change the interpolator.

SlideInLeftAnimator animator = new SlideInLeftAnimator();
animator.setInterpolator(new OvershootInterpolator());
// or recyclerView.setItemAnimator(new SlideInUpAnimator(new OvershootInterpolator(1f));
recyclerView.setItemAnimator(animator);

Advanced Step 5

By implementing AnimateViewHolder, you can override preset animation. So, custom animation can be set depending on view holder.

static class MyViewHolder extends RecyclerView.ViewHolder implements AnimateViewHolder {
  public MyViewHolder(View itemView) {
    super(itemView);
  }

  @Override
  public void preAnimateRemoveImpl(RecyclerView.ViewHolder holder) {

  }

  @Override
  public void animateRemoveImpl(RecyclerView.ViewHolder holder, ViewPropertyAnimatorListener listener) {
    ViewCompat.animate(itemView)
          .translationY(-itemView.getHeight() * 0.3f)
          .alpha(0)
          .setDuration(300)
          .setListener(listener)
          .start();
  }

  @Override
  public void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
    ViewCompat.setTranslationY(itemView, -itemView.getHeight() * 0.3f);
    ViewCompat.setAlpha(itemView, 0);
  }

  @Override
  public void animateAddImpl(RecyclerView.ViewHolder holder, ViewPropertyAnimatorListener listener) {
    ViewCompat.animate(itemView)
          .translationY(0)
          .alpha(1)
          .setDuration(300)
          .setListener(listener)
          .start();
  }
}

Animators

Cool

LandingAnimator

Scale

ScaleInAnimator, ScaleInTopAnimator, ScaleInBottomAnimator
ScaleInLeftAnimator, ScaleInRightAnimator

Fade

FadeInAnimator, FadeInDownAnimator, FadeInUpAnimator
FadeInLeftAnimator, FadeInRightAnimator

Flip

FlipInTopXAnimator, FlipInBottomXAnimator
FlipInLeftYAnimator, FlipInRightYAnimator

Slide

SlideInLeftAnimator, SlideInRightAnimator, OvershootInLeftAnimator, OvershootInRightAnimator
SlideInUpAnimator, SlideInDownAnimator

RecyclerView.Adapter

Step 1

Set RecyclerView ItemAnimator.

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
MyAdapter adapter = new MyAdapter();
recyclerView.setAdapter(new AlphaInAnimationAdapter(adapter));

Advanced Step 2

Change the durations.

MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
alphaAdapter.setDuration(1000);
recyclerView.setAdapter(alphaAdapter);

Advanced Step 3

Change the interpolator.

MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
alphaAdapter.setInterpolator(new OvershootInterpolator());
recyclerView.setAdapter(alphaAdapter);

Advanced Step 4

Disable the first scroll mode.

MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
scaleAdapter.setFirstOnly(false);
recyclerView.setAdapter(alphaAdapter);

Advanced Step 5

Multiple Animations

MyAdapter adapter = new MyAdapter();
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(adapter);
recyclerView.setAdapter(new ScaleInAnimationAdapter(alphaAdapter));

Adapters

Alpha

AlphaInAnimationAdapter

Scale

ScaleInAnimationAdapter

Slide

SlideInBottomAnimationAdapter
SlideInRightAnimationAdapter, SlideInLeftAnimationAdapter

Applications using RecyclerView Animators

Please ping me or send a pull request if you would like to be added here.

Icon Application
Ameba Ownd
QuitNow!
AbemaTV

Developed By

Daichi Furiya (Wasabeef) - dadadada.chop@gmail.com

Follow me on Twitter

Contributions

Any contributions are welcome!

Contributers

Thanks

  • Inspired by AndroidViewAnimations in daimajia.

License

Copyright 2017 Wasabeef

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Project Statistics

Sourcerank 14
Repository Size 64.5 MB
Stars 9,647
Forks 1,844
Watchers 315
Open issues 101
Dependencies 1
Contributors 22
Tags 16
Created
Last updated
Last pushed

Top Contributors See all

Daichi Furiya Eugen Martynov Afik Hiroki Oizumi Yoshihito Ikeda Yuya Tanaka Gabriele Mariotti Piasy Christopher Luc Sylvester Yao Edwin Hernandez jonathan-caryl shinwan2 scache Bitdeli Chef Andrii Luu Gia Thuy Roc Boronat Harsh B. Bhakta mrhether

Packages Referencing this Repo

Karamunting.Android.Wasabeef.RecyclerViewAnimators
An Android library that allows developers to easily create RecyclerView with animations
Latest release 3.0.0 - Updated - 9.65K stars
jp.wasabeef:recyclerview-animators
which provides simple Item animations to RecyclerView items
Latest release 2.2.6 - Updated - 9.65K stars

Recent Tags See all

3.0.0 November 16, 2018
2.3.0 February 07, 2018
2.2.7 June 29, 2017
2.2.6 March 17, 2017
2.2.5 December 02, 2016
2.2.4 September 04, 2016
2.2.2 April 05, 2016
1.3.0 September 11, 2015
1.2.0 April 15, 2015
1.1.3 April 08, 2015
1.1.2 March 22, 2015
1.1.0 February 09, 2015
1.0.3 January 21, 2015
1.0.2 January 20, 2015
1.0.1 January 09, 2015

Interesting Forks See all

mikepenz/recyclerview-animators
An Android Animation library which easily add itemanimator to RecyclerView items.
Java - Updated - 3 stars - 1 forks
vondear/recyclerview-animators
An Android Animation library which easily add itemanimator to RecyclerView items.
Java - Apache-2.0 - Updated - 2 stars - 3 forks
kaelaela/recyclerview-animators
An Android Animation library which easily add itemanimator to RecyclerView items.
Java - Apache-2.0 - Updated - 2 stars
zzz40500/recyclerview-animators
An Android Animation library which easily add itemanimator to RecyclerView items.
This repository is no longer available - 2 stars - 1 forks
Andy671/recyclerview-animators
An Android Animation library which easily add itemanimator to RecyclerView items.
Java - Last pushed - 2 stars

Something wrong with this page? Make a suggestion

Last synced: 2017-05-17 13:09:48 UTC

Login to resync this repository