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)文章
Android編程經(jīng)典代碼集錦(復(fù)制,粘貼,瀏覽器調(diào)用,Toast顯示,自定義Dialog等)
這篇文章主要介紹了Android編程經(jīng)典代碼集錦,包括Android的復(fù)制,粘貼,瀏覽器調(diào)用,Toast顯示,自定義Dialog等實(shí)現(xiàn)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2016-01-01
Android中使用IntentService創(chuàng)建后臺(tái)服務(wù)實(shí)例
這篇文章主要介紹了Android中使用IntentService創(chuàng)建后臺(tái)服務(wù)實(shí)例,IntentService提供了在單個(gè)后臺(tái)線程運(yùn)行操作的簡(jiǎn)單結(jié)構(gòu),需要的朋友可以參考下2014-06-06
Android入門之BroadCast模擬實(shí)現(xiàn)異地登錄事件發(fā)生后的主動(dòng)退出
隨著對(duì)BroadCast的越來越深入,我們今天要實(shí)現(xiàn)一個(gè)稍微復(fù)雜一點(diǎn)的BroadCast。即只允許一個(gè)設(shè)備登錄一個(gè)帳號(hào)時(shí),APP會(huì)彈一個(gè)對(duì)話框如:您的賬號(hào)在別處登錄,請(qǐng)重新登陸!感興趣的可以了解一下2022-12-12
Android使用自定義View繪制漸隱漸現(xiàn)動(dòng)畫
這篇文章主要介紹了Android使用自定義View繪制漸隱漸現(xiàn)動(dòng)畫效果的相關(guān)內(nèi)容,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
Android?Camera1實(shí)現(xiàn)預(yù)覽框顯示
這篇文章主要為大家詳細(xì)介紹了Android?Camera1實(shí)現(xiàn)預(yù)覽框顯示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android?掃碼槍輸入時(shí)屏蔽軟鍵盤和頂部狀態(tài)欄的解決方案
在Android設(shè)備上,使用掃碼槍時(shí)常遇到軟鍵盤和頂部狀態(tài)欄顯示問題,本文介紹了在Android 7.1.2版本上,如何通過設(shè)置inputType為none屏蔽軟鍵盤,以及通過hideStatusBar和NoActionBar方法隱藏頂部狀態(tài)欄,以優(yōu)化掃碼槍使用界面,這些方法有助于提升使用掃碼槍場(chǎng)景的用戶體驗(yàn)2024-10-10
android imageview圖片居中技巧應(yīng)用
做UI布局,尤其是遇到比較復(fù)雜的多重LinearLayout嵌套,常常會(huì)被一些比較小的問題困擾上半天,可是無論怎樣設(shè)置layout_gravity屬性,都無法達(dá)到效果2012-11-11

