1 public class Roundimageview extends ImageView {2 private paint paint; 3 private int roundwidth = 50; 4 private int roundheight = 50; 5 Private Paint Paint2; 6 7 Public Roundimageview (context context, AttributeSet attrs, int defstyle) {8 Super (context, Attrs, DefS Tyle); 9 init (context, attrs); Ten} public Roundimageview (context context, AttributeSet Attrs) {(context, attrs); 14 Init (context, attrs); Setroundvalue public void (float roundvalue) {roundwidth = (int) roundvalue; rou Ndheight = (int) roundvalue; The public Roundimageview (context context) {the context); init (context, NULL); 25 } @SuppressLint ("Recycle") of private void init (context context, AttributeSet Attrs) {29 30 if (attrs! = null) {TypedArray a = Context.obtainstyledattributes (Attrs, R.styleable.roundangleimAgeview); Roundwidth = A.getdimensionpixelsize (R.styleable.roundangleimageview_roundwidth, roundWidth); Roundheight = A.getdimensionpixelsize (R.styleable.roundangleimageview_roundheight, roundHeight); Density} else {float = context.getresources (). Getdisplaymetrics (). density; Roun Dwidth = (int) (roundwidth * density); PNS roundheight = (int) (roundheight * density); The new paint (); Paint.setcolor (Color.White); Paint.setantialias (TRUE); Paint.setxfermode (New Porterduffxfermode (PorterDuff.Mode.DST_OUT)); Paint2 = new Paint (); Paint2.setxfermode (NULL); @Override public void Draw (canvas canvas) {Bitmap Bitmap = Bitmap.createbitmap (getw Idth (), GetHeight (), config.argb_8888); CANVAS2 canvas = new canvas (bitmap); Super.draw (CANVAS2); Drawliftup (CanvaS2); Drawrightup (CANVAS2); Drawliftdown (CANVAS2); Drawrightdown (CANVAS2); Canvas.drawbitmap (bitmap, 0, 0, Paint2); Bitmap.recycle (); bitmap = null; Drawliftup (canvas canvas) {* * Path PATH = new Path (); Path.moveto (0, Roundheight); Path.lineto (0, 0); Path.lineto (roundwidth, 0); Path.arcto (New RECTF (0, 0, roundwidth * 2, Roundheight * 2),-90,-90); Path.close (); Canvas.drawpath (path, paint); Drawliftdown private void (canvas canvas) {Path.moveto path = new Path (); 0 , GetHeight ()-roundheight); Path.lineto (0, GetHeight ()); Path.lineto (Roundwidth, GetHeight ()); Path.arcto (New RECTF (0, GetHeight ()-roundheight * 2, 0 + roundwidth * 2, GetWidth ()), 90, 90); Path.close (); Canvas.drawpath (path, paint); 81} 82 83 private void Drawrightdown (canvas canvas) {Path PATH = new Path (), Path.moveto (GetWidth ()-Roun Dwidth, GetHeight ()); Path.lineto (GetWidth (), getheight ()); Path.lineto (GetWidth (), GetHeight ()-roundheight); Path.arcto (New RECTF (GetWidth ()-Roundwidth * 2, GetHeight ()-Roundheight * 2, GetWidth (), GetHeight ()), 0, 8 9 90); Path.close (); Canvas.drawpath (path, paint); 94 private void Drawrightup (canvas canvas) {Path PATH = new Path (), Path.moveto (ge Twidth (), roundheight); Path.lineto (getwidth (), 0); 98 Path.lineto (GetWidth ()-roundwidth, 0); Path.arcto (New RECTF (GetWidth ()-roundwidth * 2, 0, getwidth (), 0 + roundheight * 2), -90, (+); H.close (); 101 Canvas.drawpath (path, paint); 102}103 104}
Android fillet ImageView class, can be set in radians