Tutorial details

Android beginner tutorial: Part 90 - Path and ArcShape | App Code for Sale | Preview

Android beginner tutorial: Part 90 - Path and ArcShape | Android Tutorial

Drawing primitive shapes in Android using Path and ArcShape classes

Overview PAGE TOP

In this tutorial we will learn about drawing primitive shapes in Android using Path and ArcShape classes.

The Path class is similar in usage to the way shapes are drawn using AS3. It has the moveTo() and lineTo() methods that you've probably worked with before if you ever tried drawing graphics using Actionscript3.

Using this class it is possible to draw unordinary primitive shapes, like, for example, a star.

First we set up the path for the lines to follow:

Path p = new Path();
p.moveTo(50, 0);
p.lineTo(25, 100);
p.lineTo(100, 50);
p.lineTo(0, 50);
p.lineTo(75, 100);
p.lineTo(50, 0);

You can then apply the drawing to a ShapeDrawable object.

ShapeDrawable shape = new ShapeDrawable(new PathShape(p, 100, 100));


Next class is ArcShape. This one lets us draw arcs, basically. There are two values you need to pass to the ArcShape constructor - float startAngle and float sweepAngle.


ShapeDrawable shape = new ShapeDrawable(new ArcShape(0, 250));


Now we've covered all the primitive shape drawing classes.

Thanks for reading!

Reference PAGE TOP


0 Comments Leave a comment

Please login in order to leave a comment.

Newest first

to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.