垂直虚线效果

来源:互联网 发布:wings上央视知乎 编辑:程序博客网 时间:2024/04/28 23:53
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);      }}

0 0
原创粉丝点击