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