常州手机网站开发,网站的ftp帐号密码,微信网站 微信支付,做五金上哪个网站推广这篇文章主要介绍了Android动态自定义圆形进度条,需要的朋友可以参考下效果图#xff1a;A.绘制圆环#xff0c;圆弧#xff0c;文本//1.画圆环//原点坐标float circleX width / 2;float circleY width / 2;//半径float radius width / 2 - roundWidth / 2;//设置画笔的属…这篇文章主要介绍了Android动态自定义圆形进度条,需要的朋友可以参考下效果图A.绘制圆环圆弧文本//1.画圆环//原点坐标float circleX width / 2;float circleY width / 2;//半径float radius width / 2 - roundWidth / 2;//设置画笔的属性paint.setColor(roundColor);paint.setStrokeWidth(roundWidth);paint.setStyle(Paint.Style.STROKE);canvas.drawCircle(circleX, circleY, radius, paint);//2.画圆弧RectF oval new RectF(roundWidth/2,roundWidth/2,width-roundWidth/2,width - roundWidth/2);paint.setColor(roundProgressColor);canvas.drawArc(oval, 0, progress * 360 / max, false, paint);//3.画文本paint.setTextSize(textSize);paint.setColor(textColor);paint.setStrokeWidth(0);String text progress * 100 / max %;Rect bounds new Rect();paint.getTextBounds(text, 0, text.length(), bounds);canvas.drawText(text, width / 2 - bounds.width() / 2, width / 2 bounds.height() / 2, paint);B.自定义属性的具体步骤具体步骤1. 定义属性: 在values目录下创建attrs.xml2. 在布局文件中引用当前应用的名称空间3. 在自定义视图标签中使用自定义属性android:idid/rp_home_progressandroid:layout_width120dpandroid:layout_height120dpandroid:layout_gravitycenter_horizontalandroid:layout_marginTop20dpatguigu:roundColorandroid:color/darker_gray atguigu:roundProgressColorandroid:color/holo_red_darkatguigu:textColorcolor/text_progressatguigu:roundWidth10dpatguigu:textSize20sp/4. 在自定义View类的构造方法中, 取出布局中的自定义属性值//1.得到所有自定义属性的数组TypedArray typedArray context.obtainStyledAttributes(attrs, R.styleable.RoundProgress);//2.获取自定义属性的值, 如果没有指定取默认值roundColor typedArray.getColor(R.styleable.RoundProgress_roundColor, Color.RED);roundProgressColor typedArray.getColor(R.styleable.RoundProgress_roundProgressColor, Color.GREEN);textColor typedArray.getColor(R.styleable.RoundProgress_textColor, Color.GREEN);roundWidth typedArray.getDimension(R.styleable.RoundProgress_roundWidth, UIUtils.dp2px(10));textSize typedArray.getDimension(R.styleable.RoundProgress_textSize, UIUtils.dp2px(20));//3.释放资源数据typedArray.recycle();C.让圆环进度动起来1.自定义RoundProgress类中提供进度属性的getter和setter方法2.在HomeFragment的onSuccess()中以上所述是小编给大家介绍的Android动态自定义圆形进度条希望对大家有所帮助如果大家有任何疑问请给我留言小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持