• 2021/5/25


    1.今日收获内容

    自定义圆形进度条

    public class CirclePgBar extends View {
    
    
        private Paint mBackPaint;
        private Paint mFrontPaint;
        private Paint mTextPaint;
        private float mStrokeWidth = 50;
        private float mHalfStrokeWidth = mStrokeWidth / 2;
        private float mRadius = 200;
        private RectF mRect;
        private int mProgress = 0;
        //目标值,想改多少就改多少
        private int mTargetProgress = 90;
        private int mMax = 100;
        private int mWidth;
        private int mHeight;
    
    
        public CirclePgBar(Context context) {
            super(context);
            init();
        }
    
        public CirclePgBar(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public CirclePgBar(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init();
        }
    
    
        //完成相关参数初始化
        private void init() {
            mBackPaint = new Paint();
            mBackPaint.setColor(Color.WHITE);
            mBackPaint.setAntiAlias(true);
            mBackPaint.setStyle(Paint.Style.STROKE);
            mBackPaint.setStrokeWidth(mStrokeWidth);
    
            mFrontPaint = new Paint();
            mFrontPaint.setColor(Color.GREEN);
            mFrontPaint.setAntiAlias(true);
            mFrontPaint.setStyle(Paint.Style.STROKE);
            mFrontPaint.setStrokeWidth(mStrokeWidth);
    
    
            mTextPaint = new Paint();
            mTextPaint.setColor(Color.GREEN);
            mTextPaint.setAntiAlias(true);
            mTextPaint.setTextSize(80);
            mTextPaint.setTextAlign(Paint.Align.CENTER);
        }
    
    
        //重写测量大小的onMeasure方法和绘制View的核心方法onDraw()
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            mWidth = getRealSize(widthMeasureSpec);
            mHeight = getRealSize(heightMeasureSpec);
            setMeasuredDimension(mWidth, mHeight);
    
        }
    
    
        @Override
        protected void onDraw(Canvas canvas) {
            initRect();
            float angle = mProgress / (float) mMax * 360;
            canvas.drawCircle(mWidth / 2, mHeight / 2, mRadius, mBackPaint);
            canvas.drawArc(mRect, -90, angle, false, mFrontPaint);
            canvas.drawText(mProgress + "%", mWidth / 2 + mHalfStrokeWidth, mHeight / 2 + mHalfStrokeWidth, mTextPaint);
            if (mProgress < mTargetProgress) {
                mProgress += 1;
                invalidate();
            }
    
        }
    
        public int getRealSize(int measureSpec) {
            int result = 1;
            int mode = MeasureSpec.getMode(measureSpec);
            int size = MeasureSpec.getSize(measureSpec);
    
            if (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.UNSPECIFIED) {
                //自己计算
                result = (int) (mRadius * 2 + mStrokeWidth);
            } else {
                result = size;
            }
    
            return result;
        }
    
        private void initRect() {
            if (mRect == null) {
                mRect = new RectF();
                int viewSize = (int) (mRadius * 2);
                int left = (mWidth - viewSize) / 2;
                int top = (mHeight - viewSize) / 2;
                int right = left + viewSize;
                int bottom = top + viewSize;
                mRect.set(left, top, right, bottom);
            }
        }
    
    
    }



    2.遇到的问题

    圆形图标
    3.明天目标

  • 相关阅读:
    使用 Apachetop 实时监测web服务器运行状况
    Idea连接服务器docker并部署代码到docker实现一键启动
    win10上修改docker的镜像文件存储位置
    docker无法删除镜像,Error: No such container,附docker常用命令
    docker--docker基本命令使用及发布镜像
    Docker for windows pull镜像文件的安装位置改变方法
    k8s 超详细总结,面试必问
    Java大数类BigDecimal及八种舍入模式的介绍
    BigDecimal创建初始化值类型对比
    BigDecimal 小数 浮点数 精度 财务计算
  • 原文地址:https://www.cnblogs.com/qiangini/p/14909417.html
Copyright © 2020-2023  润新知