• Android自定义控件之圆形进度条ImageView


    From:http://blog.csdn.net/xiadik/article/details/41648181
    package
    com.wangran.beautiful_girl_show.view; import com.wangran.beautiful_girl_show.view.photoview.PhotoView; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Typeface; import android.util.AttributeSet; /** * 可显示进度的ImageView * @author 夏小川 */ public class ProgressImageView extends ImageView { private static final String TAG = "ProgressImageView"; private Context mContext; public static final int FONT_SIZE = 14; public static final int ROUND_WIDTH = 50; public static final int STROKE_WIDTH = 7; private int mFontSize; private int mRoundWidth; private int mStrokeWidth; private Paint mPaint; private boolean mShowProgress; private int mProgress; private float mTextY; private int mCenterX; private int mCenterY; private int mRadius; private RectF mOval; public ProgressImageView(Context context) { super(context); mContext = context; } public ProgressImageView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } private void init() { float scale = mContext.getResources().getDisplayMetrics().density; mFontSize = (int) (FONT_SIZE * scale); mRoundWidth = (int) (ROUND_WIDTH * scale); mStrokeWidth = (int) (STROKE_WIDTH * scale); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextSize(mFontSize); mCenterX = getWidth() / 2; mCenterY = getHeight() / 2; mRadius = mRoundWidth / 2; mTextY = mCenterY + mFontSize * 11.0f / 28; mOval = new RectF(mCenterX - mRadius, mCenterY - mRadius, mCenterX + mRadius, mCenterY + mRadius); } public void onDraw(Canvas canvas) { if (mShowProgress) { if (mCenterX == 0 || mCenterY == 0) { init(); } // 画最外层的大圆环 mPaint.setColor(Color.DKGRAY); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(mStrokeWidth); canvas.drawCircle(mCenterX, mCenterY, mRadius, mPaint); // 画进度百分比 mPaint.setStrokeWidth(0); mPaint.setColor(Color.WHITE); mPaint.setTypeface(Typeface.MONOSPACE); mPaint.setTextAlign(Paint.Align.CENTER); String progressStr = mProgress + "%"; canvas.drawText(progressStr, mCenterX, mTextY, mPaint); // 画圆环的进度 mPaint.setStrokeWidth(mStrokeWidth); mPaint.setColor(Color.WHITE); canvas.drawArc(mOval, 0, 360 * mProgress / 100, false, mPaint); } else { super.onDraw(canvas); } } public void startProgress() { mShowProgress = true; setProgress(0); } public void setProgress(int progress) { if (mShowProgress) { mProgress = progress; invalidate(); } } public void closeProgress() { mShowProgress = false; } }

  • 相关阅读:
    Sql server时间转时间long
    SQL Server死锁问题:事务(进程 ID x)与另一个进程被死锁在 锁 | 通信缓冲区资源上并且已被选作死锁牺牲品。请重新运行该事务。
    layui jquery ajax,url,type,async,dataType,data
    在 Postman 中报错:Self-signed SSL certificates are being blocked 的分析与解决
    SQL server CASE WHEN
    SQL server 统计分组经计
    Spring boot @Transactional
    基于mysql的sakila数据库脚本分析
    常用数据库JDBC
    在做银行支付接口案例的时候,遇到的编码问题!
  • 原文地址:https://www.cnblogs.com/niray/p/4251313.html
Copyright © 2020-2023  润新知