重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
這期內容當中小編將會給大家帶來有關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);