Imitation circular progress bar 360 android

 

Figure Town House

Painted knowledge used:

: Bezier curve

: Circle

: Draw an arc

 

/**
 * Created by xp on 2017/2/22.
 * 计算圆上任意一点  x*x+Y*Y=R*R
 * (x-a)^2+(y-b)^2=R2
 */

public class Myview extends View {
    public Myview(Context context) {
        this(context, null);
    }

    public Myview(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public Myview(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        Bessel1(context);

    }
    RectF oval1;
    private Paint mPaint;
    private PointF start, end, control;

    public void Bessel1(Context context) {

        mPaint = new Paint();

        mPaint.setStrokeWidth(1);
        mPaint.setStyle(Paint.Style.STROKE);

        mPaint.setColor(Color.parseColor("#000000"));
        start = new PointF(300, 500);
        end = new PointF(300, 500);

        control = new PointF(300, 300);
        oval1 = new RectF(control.x-Raids, control.y-Raids, control.x+Raids, control.y+Raids);
        //  mItemWaveLength = BmpDST.getWidth();

    }

    public void setstart(float statx, float staty, float stopx, float stopy) {
        start.x = statx;
        start.y = staty;
        end.x = stopx;
        end.y = stopy;
        invalidate();
    }


    int Raids = 200;
    int i = 0;
    int j = 200;




    public boolean isLeft() {
        return left;
    }

    public void setLeft(boolean left) {
        this.left = left;
        invalidate();
    }

    //三阶贝塞尔
    //  path.cubicTo((float) (start.x + (0.25 * (end.x - start.x))) + i, (float) (start.y - (0.25 * (end.x - start.x))), (float) (start.x + (0.75 * (end.x - start.x))) + i, (float) (start.y + (0.25 * (end.x - start.x))), end.x, end.y);
    boolean left;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);




        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.parseColor("#2EFF37"));
        mPaint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(control.x, control.y, Raids, mPaint);
        Path path = new Path();
        path.moveTo(start.x, start.y);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        path.moveTo(start.x, start.y);
        canvas.drawPath(path, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#2EFF37"));
        canvas.drawArc(oval1, startdu(Raids - j), 180 - 2 * startdu(Raids - j), false, mPaint);//小弧形

        if (left == true) {
            iszheng(canvas);
        } else {
            isfang(canvas);
        }

        if (j==Raids*2){

        }else {

            setstart(300 - Isx(200 - j), 500 - j, 300 + Isx(200 - j), 500 - j);
        }

    }

    public float Isx(double Y) {
        double X = 0;
        X = Math.sqrt(((Raids * Raids) - (Y * Y)));
        return Float.valueOf(X + "");

    }


    public Float startdu(double y) {
        double s2 = (Math.asin(y / Raids) / Math.PI) * 180;
        return Float.valueOf(s2 + "");

    }

    //右边
    public void iszheng(Canvas canvas) {

        Path path = new Path();
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#2EFF37"));
        path.moveTo(start.x, start.y);
        path.quadTo((float) (start.x + (0.25 * (end.x - start.x))) + i, (float) (start.y + (Raids / 5) - (0.25 * (end.x - start.x))), control.x, control.y + Raids - j);
        canvas.drawPath(path, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#ffffff"));
        Path path1 = new Path();
        path1.moveTo(control.x, control.y + Raids - j);
        path1.quadTo((float) (start.x + (0.75 * (end.x - start.x))) + i, (float) (start.y - (Raids / 5) + (0.25 * (end.x - start.x))), end.x, end.y - 1);
        canvas.drawPath(path1, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#992EFF37"));
        Path path2 = new Path();
        path2.moveTo(control.x, control.y + Raids - j);
        path2.quadTo((float) (start.x + (0.75 * (end.x - start.x))) + i, (float) (start.y + (Raids / 5) - (0.25 * (end.x - start.x))), end.x, end.y - 1);
        canvas.drawPath(path2, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#992EFF37"));
        Path path3 = new Path();
        path3.moveTo(control.x, control.y + Raids - j);
        path3.quadTo((float) (start.x + (0.75 * (end.x - start.x))) + i, (float) (start.y + (Raids / 5) + (0.25 * (end.x - start.x))) - Raids / 4, end.x, end.y - 1);
        canvas.drawPath(path3, mPaint);


    }

    //左边
    public void isfang(Canvas canvas) {

        Path path = new Path();
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#ffffff"));
        path.moveTo(start.x, start.y - 1);
        path.quadTo((float) (start.x + (0.25 * (end.x - start.x))) + i, (float) (start.y - (Raids / 5) + (0.25 * (end.x - start.x))), control.x, control.y + Raids - j);
        canvas.drawPath(path, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#2EFF37"));
        Path path1 = new Path();
        path1.moveTo(control.x, control.y + Raids - j);
        path1.quadTo((float) (start.x + (0.75 * (end.x - start.x))) + i, (float) (start.y + (Raids / 5) - (0.25 * (end.x - start.x))), end.x, end.y);
        canvas.drawPath(path1, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#992EFF37"));
        Path path2 = new Path();
        path2.moveTo(start.x, start.y);
        path2.quadTo((float) (start.x + (0.25 * (end.x - start.x))) + i, (float) (start.y + (Raids / 5) - (0.25 * (end.x - start.x))), control.x, control.y + Raids - j);
        canvas.drawPath(path2, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#992EFF37"));
        Path path3 = new Path();
        path3.moveTo(start.x, start.y);
        path3.quadTo((float) (start.x + (0.25 * (end.x - start.x))) + i, (float) (start.y + (Raids / 5) + (0.25 * (end.x - start.x))) - Raids / 4, control.x, control.y + Raids - j);
        canvas.drawPath(path3, mPaint);


    }


}

 

 

 

 

Guess you like

Origin blog.csdn.net/a1033479126/article/details/59058168