Tuesday 15 March 2016

Draw shapes using canvas in Android


android.jpeg
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.
  1. Paint paint = new Paint();
  2. paint.setColor(Color.WHITE);
  3. paint.setStyle(Paint.Style.STROKE);
  4. paint.setStrokeWidth(1);
Example of some of the methods of Canvas class
// to draw a rectangle
  1. canvas.drawRect(startX, startY, width, height, paint);
where
startX: The left side of the rectangle to be drawn
startY: The top side of the rectangle to be drawn
Here is not the end…. To read full Blog about Draw shapes using canvas in Android visit Findnerd(A Social Network for Developers).

No comments:

Post a Comment