11

How to expand space between recyclerview item while scrolling as shown below. I tried to add a custom animation in onBindViewHolder method but this solution doesn't work as I want. It looks like some animation add to RecyclerView.OnScrollListener.onScrolled method. Any idea? Thx.

Custom animation

Community
  • 1
  • 1
kazhiu
  • 749
  • 9
  • 21

1 Answers1

0

One thing we can do is hiding and showing a transparent view below ItemLayout onSrcoll

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

and in Adapter

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()
    }
kelvin
  • 1,480
  • 1
  • 14
  • 28