Showing posts with label path. Show all posts
Showing posts with label path. Show all posts
Thursday, January 29, 2015
Android beginner tutorial Part 90 Path and ArcShape
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 youve 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:
You can then apply the drawing to a ShapeDrawable object.

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.
Example:

Now weve covered all the primitive shape drawing classes.
Thanks for reading!
Read more »
The Path class is similar in usage to the way shapes are drawn using AS3. It has the moveTo() and lineTo() methods that youve 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));
shape.setIntrinsicHeight(100);
shape.setIntrinsicWidth(100);
shape.getPaint().setColor(Color.RED);
shape.getPaint().setStyle(Paint.Style.STROKE);

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.
Example:
ShapeDrawable shape = new ShapeDrawable(new ArcShape(0, 250));
shape.setIntrinsicHeight(100);
shape.setIntrinsicWidth(100);
shape.getPaint().setColor(Color.RED);

Now weve covered all the primitive shape drawing classes.
Thanks for reading!
Subscribe to:
Posts (Atom)