Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

wasabeef/recyclerview-animators

Repository files navigation

Android ArsenalLicenseMaven 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'sbuild.gradle file add this implementation statement to thedependencies section:

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

Also make sure that therepositories section includes not only"mavenCentral()" but also amaven 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 callingnotifyDataSetChanged();as it is the RecyclerView's default behavior, animations are not triggered to start inside this method.

funremove(position:Int) {  dataSet.removeAt(position)  notifyItemRemoved(position)}funadd(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.

classMyViewHolder(itemView:View) : RecyclerView.ViewHolder(itemView), AnimateViewHolder {overridefunpreAnimateRemoveImpl(holder:RecyclerView.ViewHolder) {// do something  }overridefunanimateRemoveImpl(holder:RecyclerView.ViewHolder,listener:ViewPropertyAnimatorListener) {    itemView.animate().apply {      translationY(-itemView.height*0.3f)      alpha(0f)      duration=300      setListener(listener)    }.start()  }overridefunpreAnimateAddImpl(holder:RecyclerView.ViewHolder) {    itemView.setTranslationY(-itemView.height*0.3f)    itemView.setAlpha(0f)  }overridefunanimateAddImpl(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

RecyclerViewrecyclerView =findViewById(R.id.list);recyclerView.setAdapter(newAlphaInAnimationAdapter(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

AlphaInAnimationAdapteralphaInAnimationAdapter =newAlphaInAnimationAdapter(newMyAdapter());alphaInAnimationAdapter.setDuration(1000);alphaInAnimationAdapter.setInterpolator(newOvershootInterpolator());alphaInAnimationAdapter.setFirstOnly(false);

Advanced Step 3

Multiple Animations

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

Java

recyclerView.setAdapter(newScaleInAnimationAdapter(alphaInAnimationAdapter));

Adapters

Alpha

AlphaInAnimationAdapter

Scale

ScaleInAnimationAdapter

Slide

SlideInBottomAnimationAdapter
SlideInRightAnimationAdapter,SlideInLeftAnimationAdapter

Applications using RecyclerView Animators

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

IconApplication
Ameba Ownd
QuitNow!
AbemaTV
CL

Developed By

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

Follow me on Twitter

Contributions

Any contributions are welcome!

Contributers

Thanks

  • Inspired byAndroidViewAnimations indaimajia.

License

Copyright 2020 Daichi Furiya / WasabeefLicensed 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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp