Question

I have a strange behavior on my custom ProgressBar. On Android <4.4, I get a good result. But on Android 4.4, I get artifacts while the ProgressBar is decreasing:

The colors are defined here:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@android:id/background">
    <clip>
        <shape>
            <corners android:radius="0dip" />

            <gradient
                android:angle="90"
                android:centerColor="#004676"
                android:centerY="0.75"
                android:startColor="#004676" />
        </shape>
    </clip>
</item>   
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="0dip" />

            <gradient
                android:angle="90"
                android:endColor="#ee7407"
                android:startColor="#ee7407" />
        </shape>
    </clip>
</item>

And in my custom ProgressBar class, I define it as follows:

private void init() {

    this.setMax(MAX);
    this.setProgress(MAX);
    _timer = new CountDownTimer(TIME * 1000, 100) {

        public void onTick(long millisUntilFinished) {
            decreaseProgress();
        }

        public void onFinish() {
            finished();
        }
    };
}


private void decreaseProgress() {
    this.setProgress(this.getProgress() - 1);
}

Progress upper

Does anybody have a hint for me? Thanks in advance!

Was it helpful?

Solution

I've encountered exactly the same problem on Nexus 5.

Currently I have no time to dig into source codes and find the difference, but I found it possible to suppress this issue if you invalidate your progress bar everytime right after setting progress to it.

In your situation, it should be:

private void decreaseProgress() {
   this.setProgress(this.getProgress() - 1);
   this.postInvalidate();
}

Hope this could help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top