Android自定义圆环进度条

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
package com.example.carlos.myapplication;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
/**
 * Created by carlos on 2015/10/24.
 */
public class CustomView extends View {
    private Paint mPaintBackCircle;
    private Paint mPaintFrontCircle;
    private Paint mPaintText;
    private float mStrokeWith =50;
    private float mHalfStrokeWith = mStrokeWith/2;
    private float mX = 200 + mHalfStrokeWith;
    private float mY = 200 + mHalfStrokeWith;
    private float mRadius = 200;
    private RectF mRectF;
    private int mProgess;
    public CustomView(Context context) {
        super(context);
        init();
    }
    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    private void init(){
        mPaintBackCircle = new Paint();
        mPaintBackCircle.setColor(Color.BLUE);
        mPaintBackCircle.setAntiAlias(true);
        mPaintBackCircle.setStyle(Paint.Style.STROKE);
        mPaintBackCircle.setStrokeWidth(mStrokeWith);
        mPaintFrontCircle = new Paint();
        mPaintFrontCircle.setColor(Color.YELLOW);
        mPaintFrontCircle.setAntiAlias(true);
        mPaintFrontCircle.setStyle(Paint.Style.STROKE);
        mPaintFrontCircle.setStrokeWidth(mStrokeWith);
        mPaintText = new Paint();
        mPaintText.setColor(Color.RED);
        mPaintText.setAntiAlias(true);
        mPaintText.setTextSize(50);
        mPaintText.setTextAlign(Paint.Align.CENTER);
        mRectF = new RectF(mHalfStrokeWith,mHalfStrokeWith,mRadius*2 + mHalfStrokeWith,mRadius*2 + mHalfStrokeWith);
        mProgess =75;
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(mX, mY, mRadius, mPaintBackCircle);
        canvas.drawArc(mRectF,0,270,false,mPaintFrontCircle);
        canvas.drawText(mProgess+"%",mX,mY,mPaintText);
    }
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:java 获取线程状态 判断线程是否已启动

下一篇: Java字符串工具类