How to Overlap items in LinearLayoutManager - RecyclerView (like stacking cards)

后端 未结 2 1518
旧巷少年郎
旧巷少年郎 2020-12-01 03:51


Is that possible to overlap the items from RecyclerView ?
I am trying that with LinearLayoutManager.
My requirements are just the same as in LinearLayoutM

2条回答
  •  广开言路
    2020-12-01 04:42

    You can achieve using ItemDecoration of RecyclerView

    set ItemDecoration :

    var customAdapter = CustomListAdapter()
    recyclerView.addItemDecoration(MyItemDecoration()) // here set decoration in recyclerview
    recyclerView.layoutManager = LinearLayoutManager(context)
    recyclerView.adapter = customAdapter
    

    create ItemDecoration class :

    class MyItemDecoration : RecyclerView.ItemDecoration() {
    
        private val overlapValue = -60
    
        override fun getItemOffsets(outRect : Rect, view : View, parent : RecyclerView, state : RecyclerView.State) {
            outRect.set(0, 0, 0, overlapValue)  // args is : left,top,right,bottom
        }
    }
    

提交回复
热议问题