Detect animation finish in Android's RecyclerView

后端 未结 9 1723
后悔当初
后悔当初 2020-12-29 02:31

The RecyclerView, unlike to ListView, doesn\'t have a simple way to set an empty view to it, so one has to manage it manually, making empty view vi

9条回答
  •  难免孤独
    2020-12-29 02:52

    Here's a little Kotlin extension method that builds on the answer by nibarius.

    fun RecyclerView.executeAfterAllAnimationsAreFinished(
        callback: (RecyclerView) -> Unit
    ) = post(
        object : Runnable {
            override fun run() {
                if (isAnimating) {
                    // itemAnimator is guaranteed to be non-null after isAnimating() returned true
                    itemAnimator!!.isRunning {
                        post(this)
                    }
                } else {
                    callback(this@executeAfterAllAnimationsAreFinished)
                }
            }
        }
    )
    

提交回复
热议问题