Android fillet ImageView class can set radians (simple code) _android

Source: Internet
Author: User

Nonsense not to say more, directly to everyone to paste the code, the specific code as follows:

public class Roundimageview extends ImageView {private Paint Paint; private int roundwidth =; private int roundheight
= 50;
Private Paint Paint2;  Public Roundimageview (context, AttributeSet attrs, int defstyle) {Super (context, attrs, defstyle); init (context,
ATTRS); Roundimageview (context, AttributeSet attrs) {Super (context, attrs), init (context, attrs); Setroundvalue (float roundvalue) {roundwidth = (int) roundvalue; roundheight = (int) roundvalue;} public Roundimageview (C Ontext context) {Super [context]; init (context, NULL);} @SuppressLint ("recycle") private void init (context, Attri Buteset attrs) {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); else {float density = context.getrEsources (). Getdisplaymetrics (). density;
Roundwidth = (int) (roundwidth * density);
Roundheight = (int) (roundheight * density);
} paint = 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 (GetWidth (), GetHeight (), config.argb_888
8);
Canvas canvas2 = new Canvas (bitmap);
Super.draw (CANVAS2);
Drawliftup (CANVAS2);
Drawrightup (CANVAS2);
Drawliftdown (CANVAS2);
Drawrightdown (CANVAS2);
Canvas.drawbitmap (bitmap, 0, 0, Paint2);
Bitmap.recycle ();
bitmap = null; } private void Drawliftup (Canvas Canvas) {Path PATH = new Path (); Path.moveto (0, roundheight); Path.lineto (0, 0); path.li
NeTo (roundwidth, 0);
Path.arcto (New RECTF (0, 0, roundwidth * 2, Roundheight * 2),-90,-90);
Path.close ();
Canvas.drawpath (path, paint); private void Drawliftdown (Canvas Canvas) {Path PATH = new Path (); PATh.moveto (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); } private void Drawrightdown (Canvas Canvas) {Path PATH = new Path (); Path.moveto (GetWidth ()-Roundwidth, GetHeight ()); p
Ath.lineto (GetWidth (), getheight ());
Path.lineto (GetWidth (), GetHeight ()-roundheight);
Path.arcto (New RECTF (GetWidth ()-Roundwidth * 2, GetHeight ()-Roundheight * 2, GetWidth (), GetHeight ()), 0, 90);
Path.close ();
Canvas.drawpath (path, paint); } private void Drawrightup (Canvas Canvas) {Path PATH = new Path (); Path.moveto (GetWidth (), roundheight); Path.lineto (GETW
Idth (), 0);
Path.lineto (GetWidth ()-roundwidth, 0);
Path.arcto (New RECTF (GetWidth ()-roundwidth * 2, 0, getwidth (), 0 + roundheight * 2),-90, 90);
Path.close ();
Canvas.drawpath (path, paint); }
}

OK, about the Android fillet ImageView class can set the content of radians small series to introduce to everyone here, I hope to help you!

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.