含覆盖模式、色块拼接组合模式的可渐变、可中间带文字列表的圆环进度条

Download

使用

implementation 'com.vegen.open:ProgressBar:+'

其中 '+' 请填写版本号 Download 后的最新版本

欢迎star,GitHub 地址:https://github.com/Vegen/ProgressBar

使用示例

布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:gravity="center"
    android:orientation="vertical">

    <com.vegen.open.library.ProgressBar
        android:id="@+id/spliceProgressBar"
        android:layout_width="150dp"
        android:layout_height="150dp"
        app:showPattern="percentSplice"
        app:progress_width="8dp"
        android:layout_centerInParent="true"/>

    <com.vegen.open.library.ProgressBar
        android:layout_marginTop="10dp"
        android:id="@+id/coverProgressBar"
        android:layout_width="150dp"
        android:layout_height="150dp"
        app:showPattern="percentCover"
        app:cover_bg_start_color="#F2F5F9"
        app:cover_end_color="#4FACFE"
        app:cover_start_color="#4FACFE"
        app:cover_mid_color="#00F2FE"
        app:progress_width="8dp"
        android:layout_centerInParent="true"/>

</LinearLayout>

分块模式的配置

private void initSpliceProgressBar(){
        final List<TextWithStyle> spliceTextWithStyleList = new ArrayList<>();
        TextWithStyle text1 = new TextWithStyle("测试1:¥166", 14f, 0xFF2B78F6, 166f / (166 + 66 + 36));
        spliceTextWithStyleList.add(text1);
        TextWithStyle text2 = new TextWithStyle("测试2:¥66", 14f, 0xFFF5C900, 66f / (166 + 66 + 36));
        spliceTextWithStyleList.add(text2);
        TextWithStyle text3 = new TextWithStyle("测试3:¥36", 14f, new int[]{0xFF4FACFE, 0xFF00F2FE}, 36f / (166 + 66 + 36));
        spliceTextWithStyleList.add(text3);

        spliceProgressBar.setSpliceAdapter(new ProgressBarSpliceAdapter() {
            @Override
            public List<TextWithStyle> getTextList() {
                return spliceTextWithStyleList;
            }

            @Override
            public float getLineSpace() {
                return 10;
            }

            @Override
            public boolean isShowDotFront() {
                return true;
            }

            @Override
            public int getTextGravity() {
                return ProgressBarCoverAdapter.TEXT_GRAVITY_LEFT;
            }

            @Override
            public int getStartAngle() {
                return 90;
            }
        });

覆盖模式的配置

private void initCoverProgressBar(){

        final List<TextWithStyle> coverTextWithStyleList = new ArrayList<>();

        TextWithStyle text1 = new TextWithStyle("已用:¥80.8", 16f, new int[]{0xFF4FACFE, 0xFF00F2FE});
        coverTextWithStyleList.add(text1);
        TextWithStyle text2 = new TextWithStyle("未用:¥20", 14f, 0xFFBBC2CC);
        coverTextWithStyleList.add(text2);

        coverProgressBar.setCoverAdapter(new ProgressBarCoverAdapter() {
            @Override
            public List<TextWithStyle> getTextList() {
                return coverTextWithStyleList;
            }

            @Override
            public float getLineSpace() {
                return 10;
            }

            @Override
            public boolean isShowDotFront() {
                return true;
            }

            @Override
            public int getStartAngle() {
                return (int) (180 + (1 - getProgressPercent()) / 2f * 360);
            }

            @Override
            public float getProgressPercent() {
                return 80f / (80 + 20);
            }

            @Override
            public int getTextGravity() {
                return ProgressBarCoverAdapter.TEXT_GRAVITY_CENTER;
            }
        });
    }

主要是配置好对应模式的 Adapter,使用相当简单

demo 效果如下
在这里插入图片描述

相关属性

属性名称意义类型默认值
showPattern进度条显示模式 percentCover(默认):按百分比上层覆盖下层模式,percentSplice:按百分比色块接拼组合模式enumpercentCover
progress_width进度宽度dimension8f
start_angle起始角度integermShowPattern == PATTERN_PERCENT_COVER ? (int) (180 + (1 - mProgressPercent) * mSweepAngle * 2) : 0
cover_start_color进度起始色colorColor.YELLOW
cover_mid_color进度中间色colorcover_start_color
cover_end_color进度结束色colorcover_start_color
cover_bg_start_color背景起始色colorColor.LTGRAY
cover_bg_mid_color背景中间色colorcover_bg_start_color
cover_bg_end_color背景结束色colorcover_bg_start_color
cover_percent进度值 介于0-1float0f
cover_sweep_angle扫过的角度integer360
cover_stroke_cap是否圆帽显示booleanfalse
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值