十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊
量身定制 + 運營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)Android應(yīng)用中怎么自定義一個圓形進(jìn)度條,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
A.繪制圓環(huán),圓弧,文本
//1.畫圓環(huán) //原點坐標(biāo) float circleX = width / 2; float circleY = width / 2; //半徑 float radius = width / 2 - roundWidth / 2; //設(shè)置畫筆的屬性 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);