ProgressBar,双向进度


布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <!--android:rotation="180"  旋转180度从右往左移动 progressDrawable自定义了颜色控制 -->
        <ProgressBar
            android:progressDrawable="@drawable/progressbar_a"
            android:rotation="180"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:id="@+id/id_progressbar01"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="15dp"

            />
        <ProgressBar
            android:progressDrawable="@drawable/progressbar_a"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:id="@+id/id_progressbar02"
            android:layout_width="0px"
            android:layout_weight="1"
            android:layout_height="15dp"

            />
        </LinearLayout>


</RelativeLayout>

drawable文件,这里把圆角,进度控制等全部去掉,只是简单的更改 颜色
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 背景  gradient是渐变,corners定义的是圆角 -->
    <item android:id="@android:id/background">
<clip>
<shape>
            <solid android:color="#ffffff" />
</shape>
</clip>
    </item>
    <!-- 第二条进度条颜色 -->
    <item android:id="@android:id/progress" >
<clip>
    <shape>
        <solid android:color="#0568fc" />
    </shape>
</clip>
    </item>


</layer-list>



关键代码

public class MainActivity extends Activity implements Runnable{
//实现Runnable接口
//声明线程
 private Thread th;
声明控件
 ProgressBar progressBar1;
    ProgressBar progressBar2;
//这里本来想动态改变颜色的。没成功
 // Drawable a=getResources().getDrawable(R.drawable.progressbar_a);
    //Drawable b=getResources().getDrawable(R.drawable.progressbar_b);
    private  boolean stateChage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar1 = (ProgressBar) findViewById(R.id.id_progressbar01);
        progressBar2 = (ProgressBar) findViewById(R.id.id_progressbar02);
        th=new Thread(this);
//启动线程
          th.start();

    }



    public void run() {
        while (true){
//获取初始进度值,获取最大进度值,获取第二进度值
            int current1=progressBar1.getProgress();
            int current2=progressBar2.getProgress();
            int currentMax1=progressBar1.getMax();
            int currentMax2=progressBar1.getMax();
            int secCurrent1=progressBar1.getSecondaryProgress();
            int secCurrent2=progressBar1.getSecondaryProgress();
             if (stateChage==false){
            if (current1>=currentMax1&&current2>=currentMax2){
                stateChage=true;


               
                
              //  b.setBounds(progressBar1.getProgressDrawable().getBounds());
               // progressBar1.setProgressDrawable(b);
                //progressBar2.setProgressDrawable(b);



            }else {
                progressBar1.setProgress(current1+5);
                progressBar2.setProgress(current2+5);
                progressBar1.setSecondaryProgress(secCurrent1 +5);
                progressBar2.setSecondaryProgress(secCurrent2+5);
            }
            }else {
                if (current1<=0&&current2<=0){
                    stateChage=false;
                }else {
                    progressBar1.setProgress(current1-1);
                    progressBar2.setProgress(current2-1);
                }
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值