RecyclerView添加行间距

firstOffset = mContext.getResources().getDimensionPixelOffset(R.dimen.recyclerview_firstposition_offset);

lastOffset = mContext.getResources().getDimensionPixelOffset(R.dimen.recyclerview_lastposition_offset);

public class BaseItemDecoration extends ItemDecoration{

@Override

public void getItemOffsets(Rect outRect, View view,

RecyclerView parent, State state) {

// TODO Auto-generated method stub

super.getItemOffsets(outRect, view, parent, state);

                        //if(parent.getChildPosition(view) == 0){

//        outRect.set(0, firstOffset, 0, 0);

        //}else if(parent.getChildPosition(view) == (mData.size() - 1)){

         // outRect.set(0, 0, 0, lastOffset);

                 //}

                            outRect.set(0, 0, 0, lastOffset);//每个item的底部偏移

}

}


你可能感兴趣的:(android,RecyclerView)