Drawing Lines

To draw a line we can use the following Canvas method:

Canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint);

The first two arguments specify the coordinates of the starting point of the line, the next two arguments specify the coordinates of the endpoint of the line, and the last argument specifies a Paint instance. The line that gets drawn will be one pixel thick. If we want the line to be thicker, we can specify its thickness in pixels by setting the stroke width of the Paint:

Paint.setStrokeWidth(float widthInPixels);

0 0

Post a comment