标签:
RecyclerView没有可以直接设置间距的属性,但可以用ItemDecoration来装饰一个item,所以继承重写ItemDecoration就可以实现间距了
public class SpaceItemDecoration extends RecyclerView.ItemDecoration{ private int space; public SpaceItemDecoration(int space) { this.space = space; } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if(parent.getChildPosition(view) != 0) outRect.top = space; } }
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.space); mRecyclerView.addItemDecoration(new SpaceItemDecoration(spacingInPixels));
标签:
原文地址:http://my.oschina.net/yaly/blog/515412