ProgressBar三种style

 

一、普通的ProgressBar
显示如图

<ProgressBar
        android:id="@+id/pbNormal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

二、有进度的ProgressBar

 

 

xml:设置style,Horizontal
<ProgressBar
       android:id="@+id/progress"
       android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Widget.AppCompat.ProgressBar.Horizontal" />
设置进度java文件
        final ProgressBar  bar= (ProgressBar) findViewById(R.id.progress);
        final TextView textView= (TextView) findViewById(R.id.tvProgress);
        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(j+"%"); } }); } } }.start();
链接:https://www.jianshu.com/p/3e3bcadf90ea
三、自定义有进度ProgressBar
 
progressBar进度条有两个部分组成, 背景图形加载进度图形,使用 <layer-list>标签,分别用 backgroundprogress作为两个部分的id值, 背景图形使用 <shape>加载进度图形还需要用 <clip>标签对图形 <shape>标签进行包裹;

 

res下的drawable文件夹下,创建样式
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:startColor="#fff" android:endColor="#fff"/> </shape> </item> <item android:id="@android:id/progress"> <clip><!--可裁剪对象--> <shape android:shape="rectangle"> <corners android:radius="5dp"/> <gradient android:angle="45" android:startColor="#f00" android:endColor="#f90"/> </shape> </clip> </item> </layer-list> 
布局xml,需要指定ProgressBar的style
    <ProgressBar
        android:id="@+id/progressSelf"
        android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:progressDrawable="@drawable/custom_progress" /> <TextView android:id="@+id/tvProgress" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
设置进度java文件
        final ProgressBar bar = (ProgressBar) findViewById(R.id.progressSelf);
        final TextView textView= (TextView) findViewById(R.id.tvProgress);
        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(j+"%"); } }); } } }.start(); 


链接:https://www.jianshu.com/p/3e3bcadf90ea
 
 

转载于:https://www.cnblogs.com/zhanghongxian666/p/10584075.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值