ProgressBar的使用

效果图

第一种:普通的ProgressBar

布局文件:

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" />

第二种:有进度横向的ProgressBar

布局文件:

   <ProgressBar
        android:id="@+id/mProgressBar"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:progress="12" />

代码:

        final ProgressBar bar = (ProgressBar) findViewById(R.id.mProgressBar);
        final TextView textView= (TextView) findViewById(R.id.tv_progressBar);
        new Thread(){
            @Override
            public void run() {
                int i=0;
                while(i<100){
                    i++;
                    try {
                        Thread.sleep(80);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    final int j=i;
                    bar.setProgress(i);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            textView.setText("自定义有进度ProgressBar:"+j+"%");
                        }
                    });
                }
            }a
        }.start();

第三种:自定义有进度ProgressBar

布局文件:

    <ProgressBar
        android:id="@+id/mMyProgressBar"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:progress="12"
        android:progressDrawable="@drawable/custom_progress" />

使用到的custom_progress.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape android:shape="rectangle">
            <corners android:radius="5dp" />
            <gradient
                android:endColor="#fff"
                android:startColor="#fff" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip><!--可裁剪对象-->
            <shape android:shape="rectangle">
                <corners android:radius="5dp" />
                <gradient
                    android:angle="45"
                    android:endColor="#f90"
                    android:startColor="#f00" />
            </shape>
        </clip>
    </item>
</layer-list>

项目地址: 传送门

推荐文章:
关于ProgressBar的美化问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值