溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

YCProgress自定義百分比進(jìn)度條

發(fā)布時(shí)間:2020-07-18 12:39:42 來(lái)源:網(wǎng)絡(luò) 閱讀:471 作者:楊充 欄目:移動(dòng)開(kāi)發(fā)
目錄介紹
  • 1.本庫(kù)優(yōu)勢(shì)亮點(diǎn)
  • 2.使用介紹
    • 2.1 圓環(huán)百分比進(jìn)度條
    • 2.2 直線百分比進(jìn)度條
    • 2.3 仿殺毒類(lèi)型百分比進(jìn)度條
  • 3.注意要點(diǎn)
  • 4.效果展示
  • 5.其他介紹

1.本庫(kù)優(yōu)勢(shì)亮點(diǎn)

  • 圓環(huán)百分比進(jìn)度條
    • 簡(jiǎn)便且小巧,支持設(shè)置多種屬性。可以設(shè)置內(nèi)圓和外圓的顏色,設(shè)置圓環(huán)的邊緣寬度。
    • 支持設(shè)置倒計(jì)時(shí)總時(shí)間,可以調(diào)用start開(kāi)始倒計(jì)時(shí),也可以調(diào)用stop暫停倒計(jì)時(shí),也可以自定義設(shè)置進(jìn)度
  • 仿殺毒類(lèi)型百分比進(jìn)度條
    • 支持設(shè)置多種類(lèi)型,比如設(shè)置百分比+單位類(lèi)型,或者設(shè)置空類(lèi)型【也就是不顯示中間百分比】
    • 支持設(shè)置進(jìn)度條的顏色,未更新的進(jìn)度條顏色;設(shè)置百分比文字大小,顏色;支持設(shè)置單位等多種屬性
    • 支持允許多線程訪問(wèn),對(duì)于設(shè)置setProgress,添加synchronized關(guān)鍵字修飾。設(shè)置進(jìn)度progress,如果小于0或者大于100,則拋異常。避免開(kāi)發(fā)者使用造成其他問(wèn)題。
  • 針對(duì)進(jìn)度條,對(duì)于設(shè)置color顏色的方法,增加了注解@ColorInt,限制開(kāi)發(fā)者調(diào)用color資源
  • 使用注解代替了枚舉,針對(duì)設(shè)置枚舉的方法,使用注解限制開(kāi)發(fā)者調(diào)用時(shí)傳入的類(lèi)型。具體可見(jiàn)代碼案例!
  • 注釋十分詳細(xì),作為開(kāi)源的lib庫(kù),我覺(jué)得要讓使用者一目了然。方便調(diào)用同時(shí),知道每個(gè)方法的作用。
  • 代碼量少,如果想學(xué)習(xí)并深入自定義控件,可以從簡(jiǎn)單開(kāi)始。這個(gè)項(xiàng)目就很符合!
  • 項(xiàng)目地址:https://github.com/yangchong211/YCProgress

2.使用介紹

  • 集成庫(kù):compile 'cn.yc:YCProgressLib:1.2.6'
2.1 圓環(huán)百分比進(jìn)度條
  • 在布局中

    //也可以設(shè)置布局中的attr屬性
    <com.ns.yc.ycprogresslib.CircleProgressbar
        android:id="@+id/pb_1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="進(jìn)度條" />
    
  • 使用方法

    //設(shè)置類(lèi)型
    pb_1.setProgressType(ProgressBarUtils.ProgressType.COUNT);
    //設(shè)置圓形的填充顏色
    pb_1.setInCircleColor(getResources().getColor(R.color.redTab));
    //設(shè)置外部輪廓的顏色
    pb_1.setOutLineColor(getResources().getColor(R.color.grayLine));
    //設(shè)置進(jìn)度監(jiān)聽(tīng)
    pb_1.setCountdownProgressListener(1, progressListener);
    //設(shè)置外部輪廓的顏色
    pb_1.setOutLineWidth(2);
    //設(shè)置進(jìn)度條線的寬度
    pb_1.setProgressLineWidth(5);
    //設(shè)置進(jìn)度
    pb_1.setProgress(60);
    //設(shè)置倒計(jì)時(shí)總時(shí)間
    pb_1.setTimeMillis(3000);
    //設(shè)置進(jìn)度條顏色
    pb_1.setProgressColor(getResources().getColor(R.color.colorPrimary));
    
    //開(kāi)始
    pb_1.start();
    //暫停
    pb_1.stop();
    //重新開(kāi)始
    pb_1.reStart();
2.2 直線百分比進(jìn)度條
  • 在布局中

    <com.ns.yc.ycprogresslib.NumberProgressbar
        android:id="@+id/bar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    
    <com.ns.yc.ycprogresslib.NumberProgressbar
        android:id="@+id/bar2"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:progress_max="100"
        app:progress_reached_bar_height="3dp"
        app:progress_unreached_bar_height="3dp"
        app:progress_reached_color="@color/colorPrimary"
        app:progress_unreached_color="@color/gray3"
        app:progress_text_size="14sp"
        app:progress_text_color="@color/colorAccent"
        app:progress_text_visibility="visible"/>
  • 代碼調(diào)用

    bar1 = (NumberProgressbar) findViewById(R.id.bar1);
    //設(shè)置倒計(jì)時(shí)總時(shí)間
    bar1.setTimeMillis(10000);
    //設(shè)置最大進(jìn)度條的值
    bar1.setMax(100);
    //設(shè)置進(jìn)度條文本的顏色
    bar1.setProgressTextColor(this.getResources().getColor(R.color.colorAccent));
    //設(shè)置進(jìn)度條文本的大小
    bar1.setProgressTextSize(ProgressBarUtils.sp2px(this,14));
    //設(shè)置百分比文字內(nèi)容是否可見(jiàn)
    bar1.setNumberTextVisibility(ProgressBarUtils.NumberTextVisibility.Visible);
    //設(shè)置百分比進(jìn)度條的高度
    bar1.setReachedBarHeight(10);
    //設(shè)置未更新百分比進(jìn)度條的高度
    bar1.setUnreachedBarHeight(10);
    //設(shè)置百分比進(jìn)度條的顏色
    bar1.setReachedBarColor(this.getResources().getColor(R.color.redTab));
    //設(shè)置未更新百分比進(jìn)度條的顏色
    bar1.setUnreachedBarColor(this.getResources().getColor(R.color.blackText2));
    //設(shè)置百分比進(jìn)度條的監(jiān)聽(tīng)
    bar1.setOnProgressBarListener(new OnNumberProgressListener() {
        @Override
        public void onProgressChange(int current, int max) {
    
        }
    });
    
    //開(kāi)始
    bar1.start();
    //暫停
    bar1.stop();
2.3 仿殺毒類(lèi)型百分比進(jìn)度條
  • 布局代碼
    <com.ns.yc.ycprogresslib.RingProgressBar
        android:id="@+id/bar_percent"
        android:layout_width="100dp"
        android:layout_height="100dp"/>
  • 如何調(diào)用
    bar_percent = (RingProgressBar) findViewById(R.id.bar_percent);
    //設(shè)置進(jìn)度
    bar_percent.setProgress(0);
    //設(shè)置更新進(jìn)度條顏色
    bar_percent.setDotColor(this.getResources().getColor(R.color.colorAccent));
    //設(shè)置未更新部分的進(jìn)度條顏色
    bar_percent.setDotBgColor(this.getResources().getColor(R.color.blackText));
    //設(shè)置百分比文字顏色
    bar_percent.setPercentTextColor(this.getResources().getColor(R.color.blackText1));
    //設(shè)置百分比文字大小
    bar_percent.setPercentTextSize(ProgressBarUtils.dp2px(this,16.0f));
    //設(shè)置展示的類(lèi)型
    bar_percent.setShowMode(ProgressBarUtils.RingShowMode.SHOW_MODE_PERCENT);
    //設(shè)置單位的文字內(nèi)容
    bar_percent.setUnitText("%");
    //設(shè)置單位的文字大小
    bar_percent.setUnitTextSize(ProgressBarUtils.dp2px(this,16.0f));
    //設(shè)置單位的文字顏色
    bar_percent.setUnitTextColor(this.getResources().getColor(R.color.blackText1));
  • 可以設(shè)置多種類(lèi)型
    • 第一種:百分比+單位【支持自己設(shè)置單位,比如設(shè)置%,或者設(shè)置毫秒s等】
    • 第二種:空顯示模式【也就是不顯示中間的部分】

3.注意要點(diǎn)

  • 3.1 不論是圓環(huán)進(jìn)度條還是直線進(jìn)度條,在調(diào)用setProgress設(shè)置進(jìn)度時(shí),增加了驗(yàn)證進(jìn)度的功能。因?yàn)槿绻O(shè)置值超過(guò)100或者小于0,該方法就起作用呢!
    /**
     * 驗(yàn)證進(jìn)度。
     *
     * @param progress      你要驗(yàn)證的進(jìn)度值。
     * @return              返回真正的進(jìn)度值。
     */
    private int validateProgress(int progress) {
        if (progress > 100){
            progress = 100;
        } else if (progress < 0){
            progress = 0;
        }
        return progress;
    }
  • 3.2 針對(duì)CircleProgressbar和NumberProgressbar自定義控件,如果調(diào)用start方法開(kāi)始循環(huán)執(zhí)行setProgress,程序意外銷(xiāo)毀,則注意:
    /**
     * 當(dāng)自定義控件銷(xiāo)毀時(shí),則調(diào)用該方法
     */
    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        stop();
    }
  • 項(xiàng)目地址:https://github.com/yangchong211/YCProgress

4.效果展示

  • YCProgress自定義百分比進(jìn)度條
    YCProgress自定義百分比進(jìn)度條
    YCProgress自定義百分比進(jìn)度條
    YCProgress自定義百分比進(jìn)度條
    YCProgress自定義百分比進(jìn)度條
    YCProgress自定義百分比進(jìn)度條

5.其他介紹

版本更新說(shuō)明
  • v1.0.0 更新于2016/2/10 作用于投資界下載更新進(jìn)度條,學(xué)習(xí)自定義控件
  • v1.1.1 更新于2016/8/12 針對(duì)圓環(huán)進(jìn)度條,添加自定義attr屬性
  • v1.1.2 更新于2017/3/10 針對(duì)圓環(huán)進(jìn)度條添加設(shè)置倒計(jì)時(shí)總時(shí)間,start和stop方法
  • v1.1.3 更新于2017/5/27 針對(duì)設(shè)置進(jìn)度的方法,增加校驗(yàn),不能小于0或者大于100
  • v1.2.5 更新于2018年8月24日 添加了直線百分比進(jìn)度條,針對(duì)部分方法添加注解
  • v1.2.6 更新于2018年11月30日 添加了詳細(xì)的注釋
  • v1.2.7 更新于2018/12/3 更新targetSdkVersion版本是27
  • 關(guān)于直線百分比進(jìn)度條參考了代碼家NumberProgressBar項(xiàng)目:https://github.com/daimajia/NumberProgressBar
關(guān)于博客匯總鏈接
  • 1.技術(shù)博客匯總
  • 2.開(kāi)源項(xiàng)目匯總
  • 3.生活博客匯總
  • 4.喜馬拉雅音頻匯總
  • 5.其他匯總
其他推薦
  • 博客筆記大匯總【15年10月到至今】,包括Java基礎(chǔ)及深入知識(shí)點(diǎn),Android技術(shù)博客,Python學(xué)習(xí)筆記等等,還包括平時(shí)開(kāi)發(fā)中遇到的bug匯總,當(dāng)然也在工作之余收集了大量的面試題,長(zhǎng)期更新維護(hù)并且修正,持續(xù)完善……開(kāi)源的文件是markdown格式的!同時(shí)也開(kāi)源了生活博客,從12年起,積累共計(jì)47篇[近20萬(wàn)字],轉(zhuǎn)載請(qǐng)注明出處,謝謝!
  • 鏈接地址:https://github.com/yangchong211/YCBlogs
  • 如果覺(jué)得好,可以star一下,謝謝!當(dāng)然也歡迎提出建議,萬(wàn)事起于忽微,量變引起質(zhì)變!
關(guān)于LICENSE
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI