Wednesday, September 9, 2009

Drawing customized shapes and basic shapes in Android

By extending the View Class, we can draw lot of shapes like circle, triangle, rectangle, rounded rectangle, bitmap, gradientdrawable, customized shape etc. Here I am explaining a few things about that.

Drawing circle, rectangle are straight forward, triangle we can draw using three lines. For customized shapes, we can use "Path" class in Android.

Example :

Path path = new Path();
path.moveTo(160.0f, 240.0f);
path.lineTo(140.0f, 200.0f);
path.addArc(new RectF(140, 180, 180, 220), -180, 180);
path.lineTo(160.0f, 240.0f);

This path, we will draw in canvas using,

canvas.drawPath(path, paint);

No comments:

Post a Comment