0

I want to draw lines on the screen but my application is drawing only dotted. So what should I add in my code?

List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();

public DrawView(Context context) {
    super(context);
    setFocusable(true);
    setFocusableInTouchMode(true);

    this.setOnTouchListener(this);

    paint.setColor(Color.BLUE);
    paint.setAntiAlias(true);
}

@Override
public void onDraw(Canvas canvas) {
    for (Point point : points) {
        canvas.drawCircle(point.x, point.y, 5, paint);
        // Log.d(TAG, "Painting: "+point);
    }
}

public boolean onTouch(View view, MotionEvent event) {
    // if(event.getAction() != MotionEvent.ACTION_DOWN)
    // return super.onTouchEvent(event);
    Point point = new Point();
    point.x = event.getX();
    point.y = event.getY();
    points.add(point);
    invalidate();
    Log.d(TAG, "point: " + point);
    return true;
    }
}

class Point 
{
    float x, y;
    @Override
    public String toString() {
        return x + ", " + y;
    }
}
Widor
  • 12,075
  • 6
  • 35
  • 60
sachit
  • 31
  • 1
  • 5

2 Answers2

0

Edit

Use drawLine or drawPath instead of drawCircle.

I would suggest you to take a look on the Fingerpaint example of the API Demos

Praveenkumar
  • 25,322
  • 23
  • 89
  • 166
Andreas Ka
  • 819
  • 8
  • 22
0
  1. Use drawLine bewteen 2 sets of points
  2. For smoother lines, get all the historic events in onTouch and process them first
  3. for faster/smoother, invalidate only the rect where points have changes

Read more here

yoah
  • 7,030
  • 2
  • 25
  • 30