androidRecyclerView万能分隔线在使⽤recyclerview时,经常会需要使⽤分隔线的功能,现在记录⼀下
public class RecycleViewDivider extends RecyclerView.ItemDecoration {
private Paint mPaint;
private Drawable mDivider;
private int mDividerHeight = 2;//分割线⾼度,默认为1px
private int mOrientation;//列表的⽅向:LinearLayoutManager.VERTICAL或LinearLayoutManager.HORIZONTAL
private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
/**
得意忘形什么意思
* 默认分割线:⾼度为2px,颜⾊为灰⾊
*
* @param context
* @param orientation 列表⽅向
*/
public RecycleViewDivider(Context context, int orientation) {
if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) {
团山民居throw new IllegalArgumentException("请输⼊正确的参数!");
}
普通话培训
mOrientation = orientation;
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
安逸的意思是什么
}
/**
* ⾃定义分割线
党员能移民吗*
* @param context
* @param orientation 列表⽅向
滚球* @param drawableId 分割线图⽚
*/
public RecycleViewDivider(Context context, int orientation, int drawableId) {
//this(context, orientation);
mDivider = Drawable(context, drawableId);
mDividerHeight = IntrinsicHeight();
}
/**思想上的不足
* ⾃定义分割线
*
* @param context
* @param orientation 列表⽅向
* @param dividerHeight 分割线⾼度
* @param dividerColor 分割线颜⾊
*/
public RecycleViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) {
//this(context, orientation);
mDividerHeight = dividerHeight;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.tColor(dividerColor);
mPaint.tStyle(Paint.Style.FILL);
}
//获取分割线尺⼨
@Override
public void getItemOffts(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
// outRect.t(0, 0, 0, mDividerHeight);
标的名称if (mOrientation == LinearLayoutManager.VERTICAL) {
outRect.t(0, 0, 0, mDividerHeight);
} el {
outRect.t(0, 0, mDividerHeight, 0);
}
}