Detect animation finish in Android's RecyclerView

后端 未结 9 1674
后悔当初
后悔当初 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:59

    There is a method in the ItemAnimator class that is called when all item animations are finished:

        /**
         * Method which returns whether there are any item animations currently running.
         * This method can be used to determine whether to delay other actions until
         * animations end.
         *
         * @return true if there are any item animations currently running, false otherwise.
         */
         public abstract boolean isRunning();
    

    You can override it to detect when all item animations have ended:

    recyclerView.itemAnimator = object : DefaultItemAnimator() {
        override fun isRunning(): Boolean {
            val isAnimationRunning = super.isRunning()
            if(!isAnimationRunning) {
                // YOUR CODE
            }
            return isAnimationRunning
        }
    }
    

提交回复
热议问题