Удалить украшение последнего элемента из менеджера gridlayout recyclerView

У меня есть 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)

}

person milad salimi    schedule 21.02.2021    source источник
comment
stackoverflow.com/ вопросы/46215810/   -  person ADM    schedule 21.02.2021