Android fillet ImageView class, can be set in radians

Source: Internet
Author: User

1  Public classRoundimageviewextendsImageView {2     Privatepaint paint;3     Private intRoundwidth = 50;4     Private intRoundheight = 50;5     PrivatePaint Paint2;6 7      PublicRoundimageview (context context, AttributeSet attrs,intDefstyle) {8         Super(context, attrs, defstyle);9 init (context, attrs);Ten     } One  A      PublicRoundimageview (Context context, AttributeSet attrs) { -         Super(context, attrs); - init (context, attrs); the     } -  -      Public voidSetroundvalue (floatroundvalue) { -Roundwidth = (int) Roundvalue; +Roundheight = (int) Roundvalue; -     } +  A      PublicRoundimageview (Context context) { at         Super(context); -Init (Context,NULL); -     } -  -@SuppressLint ("Recycle") -     Private voidInit (context context, AttributeSet attrs) { in  -         if(Attrs! =NULL) { toTypedArray A =context.obtainstyledattributes (Attrs, r.styleable.roundangleimageview); +Roundwidth =a.getdimensionpixelsize (R.styleable.roundangleimageview_roundwidth, roundwidth); -Roundheight =a.getdimensionpixelsize (R.styleable.roundangleimageview_roundheight, roundheight); the}Else { *             floatDensity =context.getresources (). Getdisplaymetrics (). density; $Roundwidth = (int) (Roundwidth *density);Panax NotoginsengRoundheight = (int) (Roundheight *density); -         } the  +Paint =NewPaint (); A Paint.setcolor (color.white); thePaint.setantialias (true); +Paint.setxfermode (NewPorterduffxfermode (PorterDuff.Mode.DST_OUT)); -  $Paint2 =NewPaint (); $Paint2.setxfermode (NULL); -     } -  the @Override -      Public voidDraw (canvas canvas) {WuyiBitmap Bitmap =Bitmap.createbitmap (GetWidth (), GetHeight (), config.argb_8888); theCanvas CANVAS2 =NewCanvas (bitmap); -         Super. Draw (CANVAS2); Wu Drawliftup (CANVAS2); - Drawrightup (CANVAS2); About Drawliftdown (CANVAS2); $ Drawrightdown (CANVAS2); -Canvas.drawbitmap (bitmap, 0, 0, Paint2); - bitmap.recycle (); -Bitmap =NULL; A     } +  the     Private voiddrawliftup (canvas canvas) { -Path PATH =NewPath (); $Path.moveto (0, roundheight); thePath.lineto (0, 0); thePath.lineto (roundwidth, 0); thePath.arcto (NewRECTF (0, 0, roundwidth * 2, Roundheight * 2),-90,-90); the path.close (); - Canvas.drawpath (path, paint); in     } the  the     Private voiddrawliftdown (canvas canvas) { AboutPath PATH =NewPath (); thePath.moveto (0, getheight ()-roundheight); thePath.lineto (0, GetHeight ()); the Path.lineto (Roundwidth, GetHeight ()); +Path.arcto (NewRECTF (0, GetHeight ()-roundheight * 2, 0 + roundwidth * 2, GetWidth ()), 90, 90); - path.close (); the Canvas.drawpath (path, paint);Bayi     } the  the     Private voiddrawrightdown (canvas canvas) { -Path PATH =NewPath (); -Path.moveto (GetWidth ()-Roundwidth, GetHeight ()); the Path.lineto (GetWidth (), getheight ()); thePath.lineto (GetWidth (), getheight ()-roundheight); thePath.arcto (NewRECTF (GetWidth ()-Roundwidth * 2, GetHeight ()-Roundheight * 2, GetWidth (), GetHeight ()), 0, the90); - path.close (); the Canvas.drawpath (path, paint); the     } the 94     Private voiddrawrightup (canvas canvas) { thePath PATH =NewPath (); the Path.moveto (GetWidth (), roundheight); thePath.lineto (getwidth (), 0);98Path.lineto (GetWidth ()-Roundwidth, 0); AboutPath.arcto (NewRECTF (GetWidth ()-roundwidth * 2, 0, getwidth (), 0 + roundheight * 2),-90, 90); - path.close ();101 Canvas.drawpath (path, paint);102     }103 104}

Android fillet ImageView class, can be set in radians

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.