自定义简单的进度条

来源:互联网 发布:福彩3d2016年开奖数据 编辑:程序博客网 时间:2024/05/22 00:47

初学者:
本篇基于http://blog.csdn.NET/lmj623565791/article/details/24500107
Android 自定义View (三) 圆环交替 等待效果(鸿洋)
进度条图片

主要就是ondraw()方法

{        /**         * 基于宽度,无论宽度大于高度还是小于高度         */        RectF oval = new RectF(mRingWidth, mRingWidth+(getHeight()-getWidth())/2, getWidth() -                mRingWidth,                getWidth() -                mRingWidth+(getHeight()-getWidth())/2);        if (isFrist) {            mPaint.setColor(mFristColor);            /**             * 先画一个圆             */            canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2 - mRingWidth, mPaint);            /**             * 换颜色花弧             */            mPaint.setColor(mSeconedColor);            canvas.drawArc(oval, 0, progress, false, mPaint);        } else {            mPaint.setColor(mSeconedColor);            canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2 - mRingWidth, mPaint);            mPaint.setColor(mFristColor);            canvas.drawArc(oval, 0, progress, false, mPaint);        }        TextPaint textPaint = new TextPaint();        textPaint.setTextSize(50);        textPaint.setColor(mFristColor);        progressString = String.valueOf(((int) ((float)progress/360.00f*100.00f)+1))+"%";        //将进度条转换为百分比        Rect bounds = new Rect();        textPaint.getTextBounds(progressString,0,progressString.length(), bounds);        canvas.drawText(progressString,getWidth()/2-bounds.width()/2,getHeight()                        /2+bounds.height()/2,                textPaint);    }

代码下载 android studio

原创粉丝点击