【问题标题】:ItemAnimator for RecyclerView does not workRecyclerView 的 ItemAnimator 不起作用
【发布时间】:2021-04-18 15:32:57
【问题描述】:

我想使用这些动画来为 RecyclerView 的项目设置动画: https://github.com/wasabeef/recyclerview-animators

我已经完成了所有需要的事情。但是,当我应用它们时,什么也没有发生。可能是什么问题呢? 我已将其包含在依赖项中:

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

并添加到存储库:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

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

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

我是这样使用它的:

val recyclerView = view.recyclerView
recyclerView.adapter = adapter
recyclerView.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
recyclerView.itemAnimator = SlideInUpAnimator().apply {
addDuration = 350

【问题讨论】:

    标签: android kotlin animation android-recyclerview


    【解决方案1】:

    使用这个方法

    notifyItemChanged(int) notifyItemInserted(int) notifyItemRemoved(int) notifyItemRangeChanged(int, int) notifyItemRangeInserted(int, int) notifyItemRangeRemoved(int, int)

    并以这种方式设置适配器

    recyclerView.adapter = AlphaInAnimationAdapter(适配器)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-02
      • 2014-09-02
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 2018-01-07
      相关资源
      最近更新 更多