public class DashedLineView extends View {
public DashedLineView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(40f);//布局里一般会写1dp,此处宽度不做限制
paint.setColor(getResources().getColor(R.color.bg_divider_main));
Path path = new Path();
path.moveTo(0, 0);//起始坐标
path.lineTo(0,500);//终点坐标
PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);//设置虚线的间隔和点的长度,数组的含义:先画5实线,再空5,再画5实线,再空5
paint.setPathEffect(effects);
canvas.drawPath(path, paint);
}
}
垂直虚线效果
最新推荐文章于 2021-07-21 09:35:38 发布