当前位置:网站首页>Recyclerview GridLayout bisects the middle blank area

Recyclerview GridLayout bisects the middle blank area

2022-07-06 20:21:00 CodingForAndroid

/**
 * @description  recyclerview   gridlayout  Divide the middle blank area equally 
 */
class UserGradeItemDecoration(val width:Int,val itemWidth: Int, val columns: Int,val topPadding:Int) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {

        var position = parent.getChildAdapterPosition(view);
        var totalCount = parent.adapter?.itemCount;

        //  It can be adapted to any number of columns ( Just put it down )
        var w = (width - itemWidth * columns) / (columns * (columns-1));
        var p = position % columns;
        outRect.left = (w*p);
    }

}
原网站

版权声明
本文为[CodingForAndroid]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061220141461.html