• Stars
    star
    11,393
  • Rank 2,754 (Top 0.06 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

RecyclerView Animators

Android Arsenal License Maven Central

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

Please feel free to use this.

Features

Demo

ItemAnimator

Adapters

How do I use it?

Setup

Gradle

On your module's build.gradle file add this implementation statement to the dependencies section:

dependencies {
  // Kotlin
  implementation 'jp.wasabeef:recyclerview-animators:4.0.2'
}

Also make sure that the repositories section includes not only "mavenCentral()" but also a maven section with the "google()" endpoint.

repositories {
  google()
  mavenCentral()
  jcenter()
}

ItemAnimator

Step 1

Set RecyclerView ItemAnimator.

val recyclerView = findViewById<RecyclerView>(R.id.list)
recyclerView.itemAnimator = SlideInLeftAnimator()
val recyclerView = findViewById<RecyclerView>(R.id.list)
recyclerView.itemAnimator = SlideInUpAnimator(OvershootInterpolator(1f))

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.

fun remove(position: Int) {
  dataSet.removeAt(position)
  notifyItemRemoved(position)
}

fun add(text: String, position: Int) {
  dataSet.add(position, text)
  notifyItemInserted(position)
}

Advanced Step 3

You can change the durations.

recyclerView.itemAnimator?.apply {
  addDuration = 1000
  removeDuration = 100
  moveDuration = 1000
  changeDuration = 100
}

Advanced Step 4

Change the interpolator.

recyclerView.itemAnimator = SlideInLeftAnimator().apply {
  setInterpolator(OvershootInterpolator())
}

Advanced Step 5

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

class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), AnimateViewHolder {

  override fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) {
    // do something
  }

  override fun animateRemoveImpl(holder: RecyclerView.ViewHolder, listener: ViewPropertyAnimatorListener) {
    itemView.animate().apply {
      translationY(-itemView.height * 0.3f)
      alpha(0f)
      duration = 300
      setListener(listener)
    }.start()
  }

  override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) {
    itemView.setTranslationY(-itemView.height * 0.3f)
    itemView.setAlpha(0f)
  }

  override fun animateAddImpl(holder: RecyclerView.ViewHolder, listener: ViewPropertyAnimatorListener) {
    itemView.animate().apply {
      translationY(0f)
      alpha(1f)
      duration = 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.

val recyclerView = findViewById<RecyclerView>(R.id.list)
recyclerView.adapter = AlphaInAnimationAdapter(MyAdapter())

Java

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

Advanced Step 2

recyclerView.adapter = AlphaInAnimationAdapter(MyAdapter()).apply {
  // Change the durations.
  setDuration(1000)
  // Change the interpolator.
  setInterpolator(vershootInterpolator())
  // Disable the first scroll mode.
  setFirstOnly(false)
}

Java

AlphaInAnimationAdapter alphaInAnimationAdapter = new AlphaInAnimationAdapter(new MyAdapter());
alphaInAnimationAdapter.setDuration(1000);
alphaInAnimationAdapter.setInterpolator(new OvershootInterpolator());
alphaInAnimationAdapter.setFirstOnly(false);

Advanced Step 3

Multiple Animations

val alphaAdapter = AlphaInAnimationAdapter(MyAdapter())
recyclerView.adapter = ScaleInAnimationAdapter(alphaAdapter)

Java

recyclerView.setAdapter(new ScaleInAnimationAdapter(alphaInAnimationAdapter));

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
CL

Developed By

Daichi Furiya (Wasabeef) - [email protected]

Follow me on Twitter

Contributions

Any contributions are welcome!

Contributers

Thanks

  • Inspired by AndroidViewAnimations in daimajia.

License

Copyright 2020 Daichi Furiya / 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.

More Repositories

1

awesome-android-ui

A curated list of awesome Android UI/UX libraries
48,449
star
2

glide-transformations

An Android transformation library providing a variety of image transformations for Glide.
Java
9,848
star
3

richeditor-android

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.
Java
6,155
star
4

Blurry

Blurry is an easy blur library for Android
Java
5,518
star
5

awesome-android-libraries

This is an alphabetical list of libraries for Android development, the majority being actively maintained.
5,472
star
6

picasso-transformations

An Android transformation library providing a variety of image transformations for Picasso
Java
1,693
star
7

flutter-architecture-blueprints

Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.
Dart
1,581
star
8

Takt

Takt is Android library for measuring the FPS using Choreographer.
Java
1,137
star
9

fresco-processors

An Android image processor library providing a variety of image transformations for Fresco.
Java
897
star
10

awesome-android-tools

A curated list of awesome Android Tools.
333
star
11

transformers

An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.
Kotlin
286
star
12

flutter_use

Play Flutter Hooks.
Dart
196
star
13

kotlin-mvvm

Sample for MVVM using Kotlin
Kotlin
180
star
14

droid

A command-line tool for checking Android OS version history written by Rust.
Rust
115
star
15

composable-images

The Composable Images is a library providing Jetpack Compose wrapper for Glide, Picasso, and Coil.
Kotlin
107
star
16

android-RoundedTextureView

RoundedTextureView Sample
Java
50
star
17

flutter_ua_client_hints

Provide User-Agent Client Hints to a Flutter app.
Dart
41
star
18

compose-gap

Easily adding gaps inside such as Columns and Rows for Jetpack Compose.
Kotlin
33
star
19

gifflen-sample

Bitmap color reduction and GIF encoding
C++
31
star
20

flutter_hooks_test

Simple and complete Flutter hooks testing utilities that encourage good testing practices.
Dart
30
star
21

vagrant-kali-linux

Vagrant Boxes - Kali Linux
25
star
22

NavPlayground

This is a sample of Navigation component.
Kotlin
18
star
23

version_gen

The Dart code generator for your package versions. 🎯
Dart
15
star
24

dockerfiles

A collection of Dockerfiles
Shell
12
star
25

wasabeef.jp

Build a web site using the Flutter Web.
Dart
11
star
26

import-asdf-tool-versions-action

βš’οΈ Import .tool-versions of asdf to GitHub Actions workflows.
JavaScript
11
star
27

adball

Adb All devices command
11
star
28

java-code-style

IntelliJ IDEA code style settings for Wasabeef's Java and Android projects.
6
star
29

dotfiles

Vim Script
3
star
30

wasabeef

2
star