RecyclerView控件大家肯定不陌生,已经应用有一段时间了,最近在项目中写一个GridLayout样式的RecyclerView时需要设置,item之间左右的间距,下面是我总结的一个设置间距的方法分享给大家。
下面是没间距的情况
img
想要设置item之间的间距需要自己创建一个继承自RecyclerView.ItemDecoration的类
public class RecyclerViewSpacesItemDecoration extends RecyclerView.ItemDecoration {
private HashMap mSpaceValueMap;
public static final String TOP_DECORATION = "top_decoration";
public static final String BOTTOM_DECORATION = "bottom_decoration";
public static final String LEFT_DECORATION = "left_decoration";
public static final String RIGHT_DECORATION = "right_decoration";
public RecyclerViewSpacesItemDecoration(HashMap mSpaceValueMap) {
this.mSpaceValueMap = mSpaceValueMap;
<