У меня есть recyclerView
с GridLayoutManager
, я хочу удалить последний разделитель в вертикальном и горизонтальном режимах.
Я попытался установить пусто на последнюю позицию в outRect
, но у меня это не работает.
outRect.setEmpty()
У меня есть extension
fun
вот так:
fun RecyclerView.addItemDecorationWithoutLastDivider(orientation:Int) {
addItemDecoration(object :
DividerItemDecoration(context,orientation) {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
if (parent.getChildAdapterPosition(view) == state.itemCount - 1)
outRect.setEmpty()
else
super.getItemOffsets(outRect, view, parent, state)
}
})
}
Я установил recyclerView
здесь:
recyclerView.apply {
adapter = mBankListAdapter
layoutManager = GridLayoutManager(requireContext(),3,RecyclerView.VERTICAL,false)
addItemDecorationWithoutLastDivider(DividerItemDecoration.VERTICAL)
addItemDecorationWithoutLastDivider(DividerItemDecoration.HORIZONTAL)
}