当前位置: 首页 > 软件库 > 手机/移动开发 > >

recyclerview-animators

授权协议 Apache-2.0 License
开发语言 Kotlin
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 商辰钊
操作系统 Android
开源组织
适用人群 未知
 软件概览

RecyclerView Animators

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) - dadadada.chop@gmail.com

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.
  • github中 开源库clone到本地,导入到as中后无法编译 https://github.com/wasabeef/recyclerview-animators 解决:使用链接https://download.csdn.net/download/w690333243/10425159中的gradle,替换掉项目中对应的gradle即可 在这里感谢一如既往的帮助。

 相关资料
  • 关于 RecyclerView 集成库使你在你的应用中能够使用 RecyclerViewPreloader ,它可以在用户滑动 RecyclerView 时自动加载稍微超前一些的图片。 配合使用正确的图片尺寸和高效率的磁盘缓存策略,这个库可以显著减少用户滑动图片列表时看到的加载指示器的数量。 Gradle 依赖 要使用 RecyclerView 集成库,在你的 build.gradle 文件中添加

  • 描述 动态 View 的滚动组件,用于大量数据列表场景。在 Weex 下是对 list 与 cell 的包装,它通过内部子组件复用提升了滚动列表的性能。 安装 $ npm install rax-recyclerview --save 属性 属性 类型 默认值 必填 描述 支持 onEndReachedThreshold number 500 ✘ 设置加载更多的偏移 onEndReached fu

  • 我正在将适配器移植到中 我想实现的:当用户向下滚动到我想要开始取数据的末尾附近时,我还想在末尾添加i ProgressBar视图,让用户知道更多的数据即将到来。 我在BaseAdapter中实现这一点的方式是:在上,在接近结尾时请求的视图中,我将开始获取更多数据,调用notifyDataSetChanged(以获得要显示的ProgressBar视图),然后才返回所需的视图。 我在RecyclerV

  • vue-recyclerview 是一个 Vue 超大数据列表解决方案 ,动态布局 + 自动回收解决移动端中大数据量列表的性能瓶颈。 特性 DOM recyleing Multiple column Waterflow 在线演示:https://hilongjw.github.io/vue-recyclerview/

  • Linkage-RecyclerView 是一款基于 MVP 架构开发的二级联动列表控件。它是因 “RxJava 魔法师” 这个项目的需求而存在。 在最初寻遍了 GitHub 也没有找到合适的开源库(高度解耦、可远程依赖)之后,我决心研究参考现有开源项目关于二级联动的逻辑,并自己动手编写一个 高度解耦、轻松配置、可通过 maven 仓库远程依赖 的真正的第三方库。 Linkage-Recycler

  • 我正在使用和实现一个刷卡删除。在我的函数中,我调用我的服务来删除带有API请求的元素,但为此我需要适配器给我元素的id。我重写了适配器的函数 但是,当我使用它在我的函数 我在行中遇到一个错误 虽然应该返回一个int:/