Code example for Canvas

Methods: drawLine, drawLines

0
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(10);
 
        // default 
        canvas.drawLine(30, 30, 100, 30, paint);
 
        // 直線の始端と終端で何もしません。 
        paint.setStrokeCap(Paint.Cap.BUTT);
        canvas.drawLine(30, 50, 100, 50, paint);
 
        // 直線の始端と終端を丸くします。 
        paint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawLine(30, 70, 100, 70, paint);
 
        // 直線の始端と終端を四角形にします。 
        paint.setStrokeCap(Paint.Cap.SQUARE);
        canvas.drawLine(30, 90, 100, 90, paint);
 
        // 座標の配列を指定 
        // [x0 y0 x1 y1 x2 y2 ...] 
        // 座標4つで直線1本 
        float[] pts = { 150, 30, 220, 30, 150, 50, 220, 50 };
        canvas.drawLines(pts, paint);
    } 
 
    private void drawPoint(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);