ItemAnimator для RecyclerView не работает

#android #kotlin #animation #android-recyclerview

Вопрос:

Я хочу использовать эти анимации для анимации элементов 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
 

Ответ №1:

Используйте эти методы

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

и установите адаптер таким образом

RecyclerView.адаптер = адаптер AlphaInAnimationAdapter(адаптер)