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
  • 13,003
  • 7
  • 42
  • 64
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
  • 24,084
  • 23
  • 95
  • 173
Andreas Ka
  • 839
  • 9
  • 23
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,180
  • 2
  • 30
  • 30