本文实例为大家分享了Android自定义观点渐变圆形动画的具体代码,供大家参考,具体内容如下
直接上效果图
自定义属性
attrs.xml文件
& lt; resources> & lt; declare-styleable name=" ProgressRing比; & lt; !——进度起始色——比; & lt; attr name==把丈?皃r_progress_start_color”格式比; & lt; !——进度结束色——比; & lt; attr name==把丈?皃r_progress_end_color”格式比; & lt; !——背景起始色——比; & lt; attr name==把丈?皃r_bg_start_color”格式比; & lt; !——背景中间色——比; & lt; attr name==把丈?皃r_bg_mid_color”格式比; & lt; !——背景结束色——比; & lt; attr name==把丈?皃r_bg_end_color”格式比; & lt; !——进度值介于0 - 100——比; & lt; attr name==罢?皃r_progress”格式比; & lt; !——进度宽度——比; & lt; attr=name=" pr_progress_width "格式"维度"/比; & lt; !——起始角度——比; & lt; attr name==罢?皃r_start_angle”格式比; & lt; !——扫过的角度——比; & lt; attr name==罢?皃r_sweep_angle”格式比; & lt; !——是否显示动画——比; & lt; attr name==安级?皃r_show_anim”格式比; & lt;/declare-styleable> & lt;/resources>
创建一个类ProgressRing继承自认为
公开课ProgressRing扩展视图{ 私人int progressStartColor; 私人int progressEndColor; 私人int bgStartColor; 私人int bgMidColor; 私人int bgEndColor; 私人int进展; 私人progressWidth浮动; 私人int startAngle; 私人int sweepAngle; 私人布尔showAnim; 私人int mMeasureHeight; 私人int mMeasureWidth; 私人涂料bgPaint=new涂料(油漆。ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); 私人涂料progressPaint=new涂料(油漆。ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); 私人RectF pRectF; 私人unitAngle浮动; 私人int curProgress=0; 公共ProgressRing(上下文语境,AttributeSet attrs) { 超级(上下文,attrs); TypedArray ta=上下文。obtainStyledAttributes (attrs R.styleable.ProgressRing); progressStartColor=ta.getColor (R.styleable。ProgressRing_pr_progress_start_color Color.YELLOW); progressEndColor=ta.getColor (R.styleable。ProgressRing_pr_progress_end_color progressStartColor); bgStartColor=ta.getColor (R.styleable。ProgressRing_pr_bg_start_color Color.LTGRAY); bgMidColor=ta.getColor (R.styleable。ProgressRing_pr_bg_mid_color bgStartColor); bgEndColor=ta.getColor (R.styleable。ProgressRing_pr_bg_end_color bgStartColor);=ta.getInt (R.styleable进展。ProgressRing_pr_progress, 0); progressWidth=ta.getDimension (R.styleable。ProgressRing_pr_progress_width 8 f); startAngle=ta.getInt (R.styleable。ProgressRing_pr_start_angle, 150); sweepAngle=ta.getInt (R.styleable。ProgressRing_pr_sweep_angle, 240); showAnim=ta.getBoolean (R.styleable。ProgressRing_pr_show_anim,真正的); ta.recycle (); unitAngle=(浮动)(sweepAngle/100.0); bgPaint.setStyle (Paint.Style.STROKE); bgPaint.setStrokeCap (Paint.Cap.ROUND); bgPaint.setStrokeWidth (progressWidth); progressPaint.setStyle (Paint.Style.STROKE); progressPaint.setStrokeCap (Paint.Cap.ROUND); progressPaint.setStrokeWidth (progressWidth); } @Override 保护空白> & lt; myCircle.ProgressRing android: layout_width=" 320 dp” android: layout_height=" 320 dp” android: layout_gravity=" center_horizontal " 应用:pr_bg_end_color=" # 00 ffffff” 应用:pr_bg_mid_color=" # CCCCCC” 应用:pr_bg_start_color=" # 00 ffffff” 应用:pr_progress=" 70 " 应用:pr_progress_end_color=" # F78930” 应用:pr_progress_start_color=" # 00 ffffff” 应用:pr_progress_width=?0 dp/祝辞
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。