问题描述:
网格布局显示的图片如下图效果:
很明显,第一张图片上1,4编号的间距不一致
效果图看起来明显比较和谐~(图中底色只是为了方便观看效果)
然后在网上找了一些方法,尝试了几种,最后参考和尝试了请叫我百米冲刺写的方法:
封装了MyDivider,出处:自定义RecyclerView.ItemDecoration,实现Item的等间距分割以及分割线效果
/**
* Created by SummerMay on 2018/5/11.
* RecyclerView的分隔线(网格布局)
*/
public class MyDividerItem extends RecyclerView.ItemDecoration {
private int leftRight;
private int topBottom;
public MyDividerItem(int leftRight, int topBottom) {
this.leftRight = leftRight;
this.topBottom = topBottom;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
final GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) view.getLayoutParams();
final int childPosition = parent.get