Android Custom View Draw Circle Line

Source: Internet
Author: User

Customizing a drawcircle Inherit view

To implement a construction method:

 Public drawcircle (Context context) {        Super(context);         this. Mcontext = context;    }      Public drawcircle (Context context, AttributeSet attrs) {        Super(context, attrs);         this. Mcontext = context;    }

To override the OnDraw method:

 protected  void   OnDraw (Canvas canvas) { super  .ondraw (c               Anvas);        Rimpaint  = new   Paint ();        Circlebounds  = new  RECTF (2, 2,, 52 true  );        Rimpaint.setstyle (Paint.Style.STROKE);        Rimpaint.setstrokewidth (Rimwidth);        Rimpaint.setcolor (Color.Black); Canvas.drawarc (Circlebounds, N, +,  false    //Draw line Canvas.drawline (0, 0, Rimpaint,--); 
}

If you need to redraw the view, you need to define a method, call invalidate ();

Typically, you set the method in a custom view:

 Public void Setdrawview () {        // do something        invalidate ();    }

You can redraw a custom view with X.setdrawview.

The above method can be used to achieve the animation effect generally.

PS: The code is only the interception part, in fact, the main thing is to understand the principle of the view, as well as some common methods of painting,

DrawArc (), the definition of the DrawLine () parameter can be referenced in the description document

Android Custom View Draw Circle Line

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.