Android實(shí)現(xiàn)計(jì)步進(jìn)度的環(huán)形Progress
項(xiàng)目中需要實(shí)現(xiàn)一個(gè)計(jì)步進(jìn)度的環(huán)形Progress,當(dāng)未達(dá)到設(shè)定目標(biāo)時(shí),繪制特定弧度((已實(shí)現(xiàn)步數(shù)/目標(biāo)步數(shù))*360°)的圓弧。當(dāng)已實(shí)現(xiàn)步數(shù)大于等于目標(biāo)步數(shù)時(shí)繪制整個(gè)360°圓環(huán)。
效果圖:
代碼實(shí)現(xiàn):
設(shè)置已完成步數(shù)和目標(biāo)步數(shù):
public void setStep(int stepDone, int stepGoal) { this.stepDone = stepDone; this.stepGoal = stepGoal; int progess = (stepDone * 100) / stepGoal; if (progess > 100) { setProgress(100); } else { setProgress(progess); } }
設(shè)置進(jìn)度:
public void setProgress(int progress) { this.mProgress = progress; this.invalidate(); }
設(shè)置畫筆屬性:
mPaint.setAntiAlias(true); mPaint.setColor(Color.rgb(0xe9, 0xe9, 0xe9)); canvas.drawColor(Color.TRANSPARENT); mPaint.setStrokeWidth(LINE_WIDTH_BG); mPaint.setStyle(Paint.Style.STROKE);
繪制環(huán)形和背景:
canvas.drawArc(mRectF, -90, 360, false, mPaint); mPaint.setColor(Color.rgb(0xf8, 0x60, 0x30)); canvas.drawArc(mRectF, -90, ((float) mProgress / mMaxProgress) * 360, false, mPaint);
繪制步數(shù)和單位:
mPaint.setStrokeWidth(TEXT_WIDTH); String text = stepDone + context.getString(R.string.step_unit); int textHeight = height / 4; mPaint.setTextSize(textHeight); int textWidth = (int) mPaint.measureText(text, 0, text.length()); mPaint.setStyle(Paint.Style.FILL); canvas.drawText(text, width / 2 - textWidth / 2, height / 2 + textHeight / 4, mPaint);
繪制目標(biāo)步數(shù):
String textGoal = "/" + stepGoal; int textGoalHeight = height / 8; mPaint.setTextSize(textGoalHeight); int textGoalWidth = (int) mPaint.measureText(textGoal, 0, textGoal.length()); mPaint.setStyle(Paint.Style.FILL); canvas.drawText(textGoal, width / 2 - textGoalWidth / 2, height / 2 + textHeight / 2 + textGoalHeight, mPaint);
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)環(huán)形進(jìn)度條
- Android自定義環(huán)形LoadingView效果
- Android自定義View實(shí)現(xiàn)環(huán)形進(jìn)度條的思路與實(shí)例
- Android實(shí)現(xiàn)環(huán)形進(jìn)度條的實(shí)例
- Android實(shí)現(xiàn)環(huán)形進(jìn)度條代碼
- Android應(yīng)用中炫酷的橫向和環(huán)形進(jìn)度條的實(shí)例分享
- Android中制作進(jìn)度框和環(huán)形進(jìn)度條的簡(jiǎn)單實(shí)例分享
- Android環(huán)形進(jìn)度條(安卓默認(rèn)形式)實(shí)例代碼
- android自定義環(huán)形對(duì)比圖效果
相關(guān)文章
圖解Windows環(huán)境下Android Studio安裝和使用教程
這篇文章主要介紹了圖解Windows環(huán)境下Android Studio安裝和使用教程的相關(guān)資料,需要的朋友可以參考下2015-12-12Android 實(shí)現(xiàn)單線程輪循機(jī)制批量下載圖片
這篇文章主要介紹了Android 單線程輪循機(jī)制批量下載圖片的相關(guān)資料,這里對(duì)實(shí)現(xiàn)步驟做了詳細(xì)介紹,需要的朋友可以參考下2017-07-07Android 桌面Widget開發(fā)要點(diǎn)解析(時(shí)間日期Widget)
總的來說,widget主要功能就是顯示一些信息。我們今天編寫一個(gè)很簡(jiǎn)單的作為widget,顯示時(shí)間、日期、星期幾等信息。需要顯示時(shí)間信息,那就需要實(shí)時(shí)更新,一秒或者一分鐘更新一次2013-07-07Android實(shí)現(xiàn)靜態(tài)廣播監(jiān)聽器的方法
這篇文章主要介紹了Android實(shí)現(xiàn)靜態(tài)廣播監(jiān)聽器的方法,涉及Android的廣播機(jī)制與記錄監(jiān)聽廣播信息的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07CoordinatorLayout的使用如此簡(jiǎn)單(Android)
這篇文章主要為大家詳細(xì)介紹了Android CoordinatorLayout的使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09