关于RecyclerView 设置条目间距
recyclerView本身不具备设置条目间距的属性这就需要我们重新自定义类继承RecyclerView.ItemDecoration 并重写getItemOffsets方法
最后在设置的时候调用addItemDecoration(int dimension)方法
代码如下:
package com.company.zhibo.tools;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* 作者:韩少 on 2016/11/2 18:56
* recyclerView item 的间距帮助类
*/
public class RecycleItemSpace extends RecyclerView.ItemDecoration {
private int space;
public RecycleItemSpace(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=spac
e;
}
}
}
要设置间距的recyclerView的地方调用:
:int space =getResources().getDimensionPixelSize(R.dimen.recyclerItem_list_hot);
(控件)mRecyclerView.addItemDecoration(new
ecycleItemSpace(space));`这样就搞定了。