akrolsmir
akrolsmir

Reputation: 342

Drawing polygons in XML with Android

I was looking for a way to draw a polygon, specifically a triangle, for an Android app.

I read about creating an XML file and using it in a layout for certain shapes with ShapeDrawable here, but as far as I know that only works for rectangles, ovals and rings.

I know that it's possible to draw a polygon with Path and PathShape programmatically, or to do so with OpenGL, or to draw a .png in Photoshop, but I'd much prefer a way to create one in my XML layout. Would it be possible to create a custom component to do this, for instance?

Upvotes: 5

Views: 5217

Answers (1)

Dheeraj Vepakomma
Dheeraj Vepakomma

Reputation: 28767

Perhaps you can extend Path and add custom XML attributes to the subclass that will construct a Path using lineTo(). The points of the polygon can be specified as a array reference.

Upvotes: 2

Related Questions