怎么在Android中自定义一个圆形进度条效果

  介绍

怎么在Android中自定义一个圆形进度条效果?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

Android是什么

Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。

1控件RoundProgress

package  listview.tianhetbm.p2p.ui;      import  android.content.Context;   import  android.content.res.TypedArray;   import  android.graphics.Bitmap;   import  android.graphics.BitmapFactory;   import  android.graphics.Canvas;   import  android.graphics.Color;   import  android.graphics.Paint;   import  android.graphics.RectF;   import  android.util.AttributeSet;   import  android.util.Log;   import  android.view.View;      import  listview.tianhetbm.p2p.R;         public  class  RoundProgress  extends  View  {   ,,,private  Paint  Paint =, new 油漆();      ,,,private  int  roundColor;   ,,,private  int  roundProgressColor;   ,,,private  int 输入textColor;   ,,,private  float  textSize;   ,,,private  float  roundWidth;   ,,,private  int  max =, 100;      ,,,private  int  progress =, 50;      ,,,public  RoundProgress (Context 上下文),{   ,,,,,,,这(上下文,null);   ,,,}      ,,,public  RoundProgress (Context 上下文,AttributeSet  attrs), {   ,,,,,,,这(上下文,attrs,, 0);   ,,,}      ,,,public  RoundProgress (Context 上下文,AttributeSet  attrs,, int  defStyleAttr), {   ,,,,,,,超级(上下文,attrs, defStyleAttr);   ,,,,,,,TypedArray  ta =, context.obtainStyledAttributes (R.styleable.RoundProgress attrs也);   ,,,,,,,//圆环的颜色   ,,,,,,,roundColor =, ta.getColor (Color.RED R.styleable.RoundProgress_roundColor也);   ,,,,,,,//圆环进度的颜色   ,,,,,,,roundProgressColor =, ta.getColor (Color.GREEN R.styleable.RoundProgress_roundProgressColor也);   ,,,,,,,//中间进度百分比文字字符串的颜色   ,,,,,,,textColor =, ta.getColor (Color.GREEN R.styleable.RoundProgress_textColor也);   ,,,,,,,//中间进度百分比的字符串的字体大小   ,,,,,,,textSize =, ta.getDimension (R.styleable.RoundProgress_textSize, 15);   ,,,,,,,//圆环的宽度   ,,,,,,,roundWidth =, ta.getDimension (R.styleable.RoundProgress_roundWidth,, 5);   ,,,,,,,ta.recycle ();   ,,,}      ,,@Override   ,,,protected  void  onDraw (Canvas 画布),{//第一步:绘制一个最外层的圆   ,,,,,,,paint.setColor (roundColor);   ,,,,,,,paint.setStrokeWidth (roundWidth);   ,,,,,,,paint.setStyle (Paint.Style.STROKE);   ,,,,,,,paint.setAntiAlias(真正的);   ,,,,,,,int  center =, getWidth (),/, 2;   ,,,,,,,int  radius =, (int), (center 安康;roundWidth /, 2-45);   ,,,,,,,//canvas.drawCircle(中心,中心,半径,,油漆);   ,,,,,,,RectF  oval =, new  RectF (center 安康;半径,,center 作用;半径,,center  +,半径,,center  +,半径);   ,,,,,,,canvas.drawArc(椭圆形,,135,,270,,假的,,油漆);   ,,,,,,,//第二步:绘制正中间的文本   ,,,,,,,float  textWidth =, paint.measureText(时间+ progress “%”);   ,,,,,,,paint.setColor(输入textColor);   ,,,,,,,paint.setTextSize (textSize);   ,,,,,,,paint.setStrokeWidth (0);   ,,,,,,,canvas.drawText(时间+ progress “%”;,, center 作用;textWidth /, 2, center  +, textSize /, 2,油漆);      null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在Android中自定义一个圆形进度条效果