如何在滚动时扩展RecyclerView项目之间的空间

时间:2016-04-20 06:29:51

标签: android android-recyclerview android-animation recyclerview-layout

如何在滚动时展开recyclerview项目之间的空间,如下所示。我尝试在onBindViewHolder方法中添加自定义动画,但此解决方案无法正常工作。看起来某些动画添加到RecyclerView.OnScrollListener.onScrolled方法。任何的想法? THX。

Custom animation

1 个答案:

答案 0 :(得分:0)

我们可以做的一件事是在ItemLayout onSrcoll下隐藏并显示透明视图

var scrollListener = object : OnScrollListener() {
            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)
                (list.adapter as CustomAdapter).changeState(newState)
            }
        }

并在适配器中

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        if(state == RecyclerView.SCROLL_STATE_IDLE){
            holder.view.visibility = View.GONE
        }else{
            holder.view.visibility = View.VISIBLE
        }
    }

    fun changeState(newState: Int) {
        state = newState
        notifyDataSetChanged()
    }