I recently studied Android 2D graphics. In Android, there are many ways to draw polygon. Here is a simple method.
Use path.
Path = New Path ();
Path. moveTo (50, 50 );
Path. lineto (100, 50 );
Path. lineto (100, 0 );
Path. lineto (150, 0 );
Path. lineto (150, 50 );
Path. lineto (200, 50 );
Path. lineto (200,100 );
Path. lineto (250,100 );
Path. lineto (250,150 );
Path. lineto (200,150 );
Path. lineto (200,200 );
Path. lineto (150,200 );
Path. lineto (150,250 );
Path. lineto (100,250 );
Path. lineto (100,200 );
Path. lineto (50,200 );
Path. lineto (50,150 );
Path. lineto (0,150 );
Path. lineto (0,100 );
Path. lineto (50,100 );
Path. Close ();
// Generate a polygon
Mdrawable = new shapedrawable (New pathshape (path, 250,250 ));
// Mdrawable. getpaint (). setcolor (color. Red );
Bitmap bitmap = bitmapfactory. decoderesource (this. getresources (), R. drawable. test );
Bitmap b1 = bitmap. createbitmap (bitmap, 0, 0,250,250); // generate a bitmap that matches the polygon size to avoid resolution problems.
Shader ashader = new bitmapshader (B1, shader. tilemode. Repeat, shader. tilemode. Repeat );
Mdrawable. getpaint (). setshader (ashader); // fill the bitmap
Mdrawable. setbounds (250,250,); // you can specify the boundary size.
Final generation
Original address: http://www.xiaojxiao.net /? P = 49