1 首先 算出跨度分割线占用的区域
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
outRect.set(0,0,100,100);//相当于paddingTop100,和paddingButton 100
}
2:再画出分割线
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
int count = parent.getChildCount();//对每一个偏移区域画
for (int i = 0;i<count;i++){
View view = parent.getChildAt(i);
int left = view.getLeft();
int top = view.getTop();
int right = view.getRight();
int bottom = view.getBottom();
Rect rect = new Rect(left,bottom,right,bottom + 1);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
c.drawRect(rect,paint);
}
}