Customization of Android View

Source: Internet
Author: User

public class Yanghangcreditcircle extends View {private static final String TAG = "Yanghangcreditcircle";    private int resid = r.drawable.credit_report_turntable;        Public Yanghangcreditcircle (Context context) {super (context);    Init ();        } public Yanghangcreditcircle (context context, AttributeSet Attrs) {Super (context, attrs);        TypedArray t = GetContext (). Obtainstyledattributes (attrs,r.styleable.yanghangcreditcircle);        Resid = T.getresourceid (r.styleable.yanghangcreditcircle_itembackground,r.drawable.credit_report_turntable);    Init ();        } private void Init () {progresspen = new Paint ();        Progresspen.setantialias (TRUE);        Progresspen.setstyle (Paint.Style.STROKE);        Progresspen.setcolor (Color.White); Progresspen.setstrokewidth (margin);//The width margin of the brush box, the brush from the middle circlebmp = Bitmapfactory.decoderesource (Getresources (),        RESID);    Bmppaint.setantialias (TRUE);   }//private float outsidepensize; Private Paint Progresspen;    Private Bitmap circlebmp;    private float degress = 0;    float margin = UIUtil.INSTANCE.DipToPixels (10);    Private Paint Bmppaint = new paint (); @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {Float width = Circlebmp.getwid        Th () + (margin) * 2;        float height = circlebmp.getheight () + (margin) * *;        Widthmeasurespec = Measurespec.makemeasurespec ((int) width, measurespec.exactly);        Heightmeasurespec = Measurespec.makemeasurespec ((int) height, measurespec.exactly);    Setmeasureddimension (Widthmeasurespec, Heightmeasurespec);        } public void setprogress (float degress) {this.degress = 5f + 205f*degress;        Postinvalidate ();//Refresh OnDraw} public void setdegressprogress (float degress) {this.degress = degress;    Postinvalidate ();     }//(0,700] e//(700,840] d//(840,890] c//(890,930] b//(930,1000] A @OverrIDE public void OnDraw (canvas canvas) {super.ondraw (canvas);        Rect rect = new rect ();        Getdrawingrect (rect);        int bmpwidth = (int) (Circlebmp.getwidth ()/2.0f);        int bmpheight = (int) (Circlebmp.getheight ()/2.0f);        Rect dstrect = new rect (); Dstrect.set (Rect.centerx ()-Bmpwidth, Rect.centery ()-Bmpheight, Rect.centerx () + Bmpwidth, Rect.centery ( ) + bmpheight), target area on//canvas rectf outsidecirclerect = new RECTF (Dstrect.left + MARGIN/2, Dstrect.top + MARGIN/2,        Dstrect.left + dstrect.width ()-MARGIN/2, Dstrect.top + dstrect.width ()-MARGIN/2);        Canvas.drawbitmap (circlebmp, NULL, dstrect, bmppaint);//Displays the entire picture in a specific rectangular area progresspen.setalpha (100);        Canvas.drawarc (Outsidecirclerect, 160f, degress, False, Progresspen);        float tmpdegress = degress;    Canvas.save (); }}

  

Customization of Android View

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.