NumberProgressBar酷炫进度条

开源项目NumberProgressBar

原地址:https://github.com/daimajia/NumberProgressBar

eclipse环境demo下载

http://download.csdn.net/detail/yang786654260/8662541
实例

自定义progressBar控件

自定义控件
直接copy到项目中使用。

自定义属性

创建attrs.xml 用来自定义属性名,源码需要

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="NumberProgressBar">
        <attr name="progress" format="integer"/>
        <attr name="max" format="integer"/>

        <attr name="progress_unreached_color" format="color"/>
        <attr name="progress_reached_color" format="color"/>

        <attr name="progress_reached_bar_height" format="dimension"/>
        <attr name="progress_unreached_bar_height" format="dimension"/>

        <attr name="progress_text_size" format="dimension"/>
        <attr name="progress_text_color" format="color"/>

        <attr name="progress_text_offset" format="dimension"/>

        <attr name="progress_text_visibility" format="enum">
            <enum name="visible" value="0"/>
            <enum name="invisible" value="1"/>
        </attr>
    </declare-styleable>

    <declare-styleable name="Themes">
        <attr name="numberProgressBarStyle" format="reference"/>
    </declare-styleable>
</resources>

自定义样式

创建style样式

<style name="NumberProgressBar_Default">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_width">match_parent</item>

        <item name="max">100</item>
        <item name="progress">0</item>

        <item name="progress_unreached_color">#CCCCCC</item>
        <item name="progress_reached_color">#3498DB</item>

        <item name="progress_text_size">10sp</item>
        <item name="progress_text_color">#3498DB</item>

        <item name="progress_reached_bar_height">1.5dp</item>
        <item name="progress_unreached_bar_height">0.75dp</item>
    </style>

reached和unreached属性请看下图:
reached

在布局中的使用

<com.daimajia.numberprogressbar.NumberProgressBar
            android:id="@+id/numberbar1"
            style="@style/NumberProgressBar_Default"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="20dp"
            custom:progress="0" />

在代码中的使用

public class MainActivity extends Activity {

    private int counter = 0;
    private Timer  timer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final NumberProgressBar npb1 = (NumberProgressBar) findViewById(R.id.numberbar1);

        counter = 0;
        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        npb1.incrementProgressBy(1);//进度的增加量
                        counter ++;
                        if (counter == 110) {
                            npb1.setProgress(0);//设置进度
                            counter = 0;
                        }
                    }
                });

            }
        }, 1000, 100);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值