100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android RecyclerView 九宫格布局上下均分

android RecyclerView 九宫格布局上下均分

时间:2019-01-23 12:09:05

相关推荐

android RecyclerView 九宫格布局上下均分

今天有人问到这方面问题,趁着礼拜天 分享给大家 ,直接上代码

首先先将下面的复制的你的代码中

public class ItemOffsetDecoration extends RecyclerView.ItemDecoration {private int mItemOffset;public ItemOffsetDecoration(int itemOffset) {mItemOffset = itemOffset;}public ItemOffsetDecoration(Context context, int itemOffsetId) {this(context.getResources().getDimensionPixelSize(itemOffsetId));}@Overridepublic void getItemOffsets(Rect outRect, View view, RecyclerView parent,RecyclerView.State state) {super.getItemOffsets(outRect, view, parent, state);outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset);}}

他的使用如下

recyclerView.setLayoutManager(new GridLayoutManager(this, 4));ItemOffsetDecoration itemOffsetDecoration = new ItemOffsetDecoration(this, R.dimen.dp_5);recyclerView.addItemDecoration(itemOffsetDecoration);adapter = new GridAdapter(list);

效果图demo地址。。。。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。