多色进度条Android

时间:2017-02-24 18:47:47

标签: android xml progress-bar

我知道这个问题已被提出但我无法弄清楚我的问题。 我想创建一个进度条,在进度过程中会有三种颜色。 它将以蓝色开始,经过40%的进展后,它将平稳地变为橙色,75%后,它将平稳地变为红色。

我有一个可绘制的背景和一个颜色的进展:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/background">
    <shape>
        <gradient
            android:startColor="#666666"
            android:centerColor="#808080"
            android:endColor="#999999"
            android:centerY="1.0"
            android:angle="270"/>
        <corners android:radius="10dip"/>
    </shape>
</item>

<item android:id="@+id/progress">
    <clip>
        <shape>
            <corners android:radius="10dip"/>
            <gradient
                android:startColor="#0099e6"
                android:centerY="0.75"
                android:angle="270" />
        </shape>
    </clip>
</item>
</layer-list>

我动态创建进度条:

    Drawable drawable = getResources().getDrawable(R.drawable.progressbar_style);
    progressBar.setProgressDrawable(drawable);
    progressBar.setMax(100);

    new Thread(new Runnable() {
        @Override
        public void run() {
            while (progressStatus < 60){
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        progressBar.setProgress(progressStatus);
                    }
                });
                try{
                    Thread.sleep(20);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                progressStatus++;
            }
        }
    }).start();

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我唯一想到的就是设置 android:angle =“0”。

相关问题