Android minutes teach you to write a personalized loading box

Source: Internet
Author: User

Idle to have nothing to write a load box, the implementation of the effect is as follows:


Implementation ideas:

In fact, it seems to feel very simple ... It's OK to draw with OnDraw in custom relativelayout.

Reviewed the knowledge that I had learned before.


Code implementation:

Package Com.whale.nangua.toquan.view;import Android.content.context;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.util.attributeset;import Android.util.Log; Import Android.view.layoutinflater;import android.widget.relativelayout;import com.whale.nangua.toquan.r;/** * Created by Nangua on 2016/8/10.    */public class Ngloaddialog extends Relativelayout {float scale;     Pixel density float height;       control height float with; Control width @Override protected void OnLayout (Boolean changed, int l, int t, int r, int b) {super.onlayout (change        D, L, T, R, b);        Height = this.getheight ();        with = This.getwidth ();        Circle_r = WITH/3/3/2;        float temp = CIRCLE_R/6;        CIRCLE_R1 = Circle_r;        CIRCLE_R2 = circle_r-temp;        CIRCLE_R3 = circle_r-2*temp;    Circle_space = 1 * scale;        } public Ngloaddialog (context context, AttributeSet Attrs) {Super (context, attrs); LaYoutinflater.from (context). Inflate (R.layout.dialog_load, this, true);       Scale = Context.getresources (). Getdisplaymetrics (). density;    Get pixel density init (); } private void Init () {} private float Circle_r;    Ball radius private float circle_space;//ball pitch private float circle_r1;    Ball 1 radius private float circle_r2;    Ball 2 radius private float CIRCLE_R3;    Ball 3 radius Private Boolean circle_r1_state = true;    Ball 1 state, true decrease false to increase private Boolean circle_r2_state = true;    Ball 2 state, true decrease false to increase private Boolean circle_r3_state = true;        Ball 3 state, true decrease false to increase @Override protected void OnDraw (canvas canvas) {super.ondraw (canvas);        Paint paint = new paint ();        Paint.setcolor (Color.White);        Paint.setantialias (TRUE);        Paint.setstrokewidth (Circle_r);        Paint.setstyle (Paint.Style.FILL);                Draw three circles//first canvas.drawcircle (WITH/2-2 * circle_r-circle_space, HEIGHT/3,   CIRCLE_R1,             Paint);            if (circle_r1_state) {circle_r1 = circle_r1-0.5f;            if (circle_r1 <= circle_r/2) {circle_r1_state = false;            }} else {circle_r1 = circle_r1 + 0.5f;            if (circle_r1 >= circle_r) {circle_r1_state = true;                }}//Second canvas.drawcircle (WITH/2, HEIGHT/3, CIRCLE_R2,        Paint);            if (circle_r2_state) {circle_r2 = circle_r2-0.5f;            if (circle_r2 <= circle_r/2) {circle_r2_state = false;            }} else {circle_r2 = circle_r2 + 0.5f;            if (circle_r2 >= circle_r) {circle_r2_state = true;                }}//Third canvas.drawcircle (WITH/2 + 2 * circle_r + circle_space, HEIGHT/3,        CIRCLE_R3, paint); if (CIrcle_r3_state) {circle_r3 = circle_r3-0.5f;            if (Circle_r3 <= circle_r/2) {circle_r3_state = false;            }} else {circle_r3 = Circle_r3 + 0.5f;            if (Circle_r3 >= circle_r) {circle_r3_state = true;    }} postinvalidatedelayed (30); }}


Android minutes teach you to write a personalized loading box

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.