Android plotting Path-like acceleration Ball Surface Fluctuation

Source: Internet
Author: User

Android plotting Path-like acceleration Ball Surface Fluctuation

The Path class provided by android can be connected to a path on the View in advance, and then the drawPath (Path, paint) of Canvas can be called and drawn along the path;
[1] draw a triangle

// Path. moveTo (100,100); // path. lineTo (0,200); // path. lineTo (200,200); // path. close (); // connect the beginning and end of the connection // canvas. drawPath (path, paint); // canvas. drawTextOnPath (path, 0, 0, painting along this line );

[Drawing the besell curve]

// Besserl curve // path. moveTo (100,100); // path. quadTo (100,400,300,300); // two points: Control Point; End Point // canvas. drawPath (path, paint); // canvas. drawPoint (100,100, paintPoint); // canvas. drawPoint (100,400, paintPoint); // canvas. drawPoint (300,300, paintPoint );

[Effect of Water Fluctuation imitation]

public class MyPathView extends View {    private Paint paint;    private Path path;    private Paint paintPoint;    private int width;    private int height;    private int count = 0;    private int size = 0;    private boolean isAdd=true;    private Handler handler = new Handler() {        @Override        public void handleMessage(Message msg) {            super.handleMessage(msg);            switch (msg.what){                case 0x23:                    count+=5;                    if(count>=80){                        count=0;                    }                    if (isAdd){                        size++;                        if(size>10){                            isAdd = false;                        }                    }else{                        size--;                        if(size<=-10){                            isAdd =true;                        }                    }                    invalidate();                    sendEmptyMessageDelayed(0x23,100);                    break;            }        }    };    public MyPathView(Context context, AttributeSet attrs) {        super(context, attrs);        paint = new Paint();        paint.setAntiAlias(true);        paint.setTextSize(30);        paint.setStyle(Paint.Style.STROKE);        paintPoint = new Paint();        paintPoint.setStrokeWidth(10);        paintPoint.setColor(Color.GREEN);        paintPoint.setStyle(Paint.Style.FILL);        path = new Path();        handler.sendEmptyMessageDelayed(0x23, 1000);    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        path.reset();        path.moveTo(count, 100);        for (int i = 0; i < 10; i++) {            path.rQuadTo(20, 20, 40, 0);            path.rQuadTo(20, -20, 40, 0);        }        canvas.drawPath(path, paint);        canvas.drawRect(200, 0, 400, 200, paint);    }    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        super.onMeasure(widthMeasureSpec, heightMeasureSpec);        width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);        height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);        setMeasuredDimension(width, height);    }}

Layout


      
   
  

 

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.