点線をCanvasに描画する
点線を描画するサンプル。drawLine()以外の描画処理でも使えるようです。
初期化処理{ Paint mDotPaint = new Paint(); mDotPaint.setPathEffect(new DashPathEffect(new float[]{ 5.0f, 5.0f }, 0)); // 5pixel描いたら5pixel描かないを繰り返す mDotPaint.setStyle(Paint.Style.STROKE); // スタイルは線(Stroke)を指定する mDotPaint.setStrokeWidth(1); // 線の太さ mDotPaint.setColor(0xffb8b8b8); // 線の色 } @Override protected void onDraw(Canvas canvas) { int width = getMeasuredWidth(); int height = getMeasuredHeight(); canvas.drawLine(15, height/2, width-16, height/2, mDotPaint); // 左右15pixel空けて中心を通る横の点線を描画する canvas.drawLine(width/2, 15, width/2, height-16, mDotPaint); // 上下15pixel空けて中心を通る縦の点線を描画する }