Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 532
akrolsmir Avatar asked Nov 04 '22 03:11

akrolsmir


1 Answers

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.

like image 99
Dheeraj Vepakomma Avatar answered Nov 14 '22 23:11

Dheeraj Vepakomma