android弧形进度条,有详细注释的,比较简单,感兴趣的朋友可以来看看。
Android 弧形进度条_第1张图片

Java code ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 package com.demo.eric.views; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; /** *弧形进度条 * *@authorEric * */ public class ArcProgressbar extends View{ public ArcProgressbar(Contextcontext){ super (context); } public ArcProgressbar(Contextcontext,AttributeSetattrs){ super (context,attrs); } @Override protected void onDraw(Canvascanvas){ super .onDraw(canvas); init(canvas); } private void init(Canvascanvas){ //画弧形的矩阵区域。 rectBg= new RectF( 15 , 15 ,diameter,diameter); //计算弧形的圆心和半径。 int cx1=(diameter+ 15 )/ 2 ; int cy1=(diameter+ 15 )/ 2 ; int arcRadius=(diameter- 15 )/ 2 ; //ProgressBar结尾和开始画2个圆,实现ProgressBar的圆角。 mPaintCircle= new Paint(); mPaintCircle.setAntiAlias( true ); mPaintCircle.setColor(bgColor); canvas.drawCircle( ( float )(cx1+arcRadius*Math.cos(startAngle* 3.14 / 180 )), ( float )(cy1+arcRadius*Math.sin(startAngle* 3.14 / 180 )), bgStrokeWidth/ 2 ,mPaintCircle); //小圆 canvas.drawCircle( ( float )(cx1+arcRadius *Math.cos(( 180 -startAngle)* 3.14 / 180 )), ( float )(cy1+arcRadius *Math.sin(( 180 -startAngle)* 3.14 / 180 )), bgStrokeWidth/ 2 ,mPaintCircle); //小圆 //弧形背景。 mPaintBg= new Paint(); mPaintBg.setAntiAlias( true ); mPaintBg.setStyle(Style.STROKE); mPaintBg.setStrokeWidth(bgStrokeWidth); mPaintBg.setColor(bgColor); canvas.drawArc(rectBg,startAngle,endAngle, false ,mPaintBg); //弧形小背景。 if (showSmallBg){ mPaintSmallBg= new Paint(); mPaintSmallBg.setAntiAlias( true ); mPaintSmallBg.setStyle(Style.STROKE); mPaintSmallBg.setStrokeWidth(barStrokeWidth); mPaintSmallBg.setColor(smallBgColor); canvas.drawArc(rectBg,startAngle,endAngle, false ,mPaintSmallBg); } //弧形ProgressBar。 mPaintBar= new Paint(); mPaintBar.setAntiAlias( true ); mPaintBar.setStyle(Style.STROKE); mPaintBar.setStrokeWidth(barStrokeWidth); mPaintBar.setColor(barColor); canvas.drawArc(rectBg,startAngle,progress, false ,mPaintBar); //随ProgressBar移动的圆。 if (showMoveCircle){ mPaintCircle.setColor(barColor); canvas.drawCircle( ( float )(cx1+arcRadius *Math.cos(angleOfMoveCircle* 3.14 / 180 )), ( float )(cy1+arcRadius *Math.sin(angleOfMoveCircle* 3.14 / 180 )), bgStrokeWidth/ 2 ,mPaintCircle); //小圆 } invalidate(); } /** * *@paramprogress */ public void addProgress( int _progress){ progress+=_progress; angleOfMoveCircle+=_progress; System.out.println(progress); if (progress>endAngle){ progress= 0 ; angleOfMoveCircle=startAngle; } invalidate(); } /** *设置弧形背景的画笔宽度。 */ public void setBgStrokeWidth( int bgStrokeWidth){ this .bgStrokeWidth=bgStrokeWidth; } /** *设置弧形ProgressBar的画笔宽度。 */ public void setBarStrokeWidth( int barStrokeWidth){ this .barStrokeWidth=barStrokeWidth; } /** *设置弧形背景的颜色。 */ public void setBgColor( int bgColor){ this .bgColor=bgColor; } /** *设置弧形ProgressBar的颜色。 */ public void setBarColor( int barColor){ this .barColor=barColor; } /** *设置弧形小背景的颜色。 */ public void setSmallBgColor( int smallBgColor){ this .smallBgColor=smallBgColor; } /** *设置弧形的直径。 */ public void setDiameter( int diameter){ this .diameter=diameter; } /** *是否显示小背景。 */ public void setShowSmallBg( boolean showSmallBg){ this .showSmallBg=showSmallBg; } /** *是否显示移动的小圆。 */ public void setShowMoveCircle( boolean showMoveCircle){ this .showMoveCircle=showMoveCircle; } private int bgStrokeWidth= 44 ; private int barStrokeWidth= 15 ; private int bgColor=Color.GRAY; private int barColor=Color.RED; private int smallBgColor=Color.WHITE; private int progress= 0 ; private int angleOfMoveCircle= 140 ; //移动小园的起始角度。 private int startAngle= 140 ; private int endAngle= 260 ; private PaintmPaintBar= null ; private PaintmPaintSmallBg= null ; private PaintmPaintBg= null ; private PaintmPaintCircle= null ; private RectFrectBg= null ; /** *直徑。 */ private int diameter= 450 ; private boolean showSmallBg= true ; //是否显示小背景。 private boolean showMoveCircle= true ; //是否显示移动的小园。 }

更多相关文章

  1. Android 设置桌面背景
  2. android studio 更改背景和设置字体大小
  3. Android设置背景图像重复【整理自网络】
  4. [学习记录]android 状态栏背景修改为透明
  5. Android ListView 去除边缘阴影、选中色、拖动背景色、行高、add
  6. ExpandableListView设置选中child的背景
  7. LinearLayout按下(pressed)或获取焦点(focused)时背景设置不同颜

随机推荐

  1. Android(安卓)第一次启动全屏时出现短暂
  2. Android EditText得到焦点失去焦点处理方
  3. Android仿微信activity滑动关闭
  4. android 常用系统修改和设置
  5. 向SD卡写文件
  6. 2.20 android连接wifi,解决mWifiManager.a
  7. 相机 android java.lang.RuntimeExceptio
  8. appcompat-v7 版本造成的问题No resource
  9. Android 基础布局控件自定义view使用练习
  10. Android中发送短信和彩信