Draw shapes using canvas in Android
We can create custom view by extending View class. The most important part of custom view is its appearance. We can give any shape to a custom view by overriding onDraw(Canvas canvas) method. Canvas class provide us many method which help us to draw any time of shape. For draw anything via Canvas class we need the object of Paint class.
- Paint paint = new Paint();
Example of some of the methods of Canvas class
// to draw a rectangle
- canvas.drawRect(startX, startY, width, height, paint);
startX: The left side of the rectangle to be drawn
startY: The top side of the rectangle to be drawn