5

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?

Community
  • 1
  • 1
akrolsmir
  • 312
  • 1
  • 4
  • 14

1 Answers1

2

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.

Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104