I\'m trying to implement a smooth animation for my ProgressBar
, but when I increase the time (30 seconds), the animation is no longer smooth.
Example wi
<ProgressBar
android:id="@+id/progress_bar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:indeterminate="false"
android:progress="0"
android:max="100"/>
@BindView(R.id.progress_bar) ProgressBar progressBar;
ObjectAnimator.ofInt(progressBar, "progress", 79).start();
79
Because you are using ofInt
you can only move at full integers. In other words, if you have a progress bar with a width of 1000 and a progress of 0 to 100 since you are moving at an integer pace you count 1, 2, 3, 4 which translates to 10px, 20px, 30px and 40px. Which explains the jaggedness you are seeing.
To correct this you have a few options. The first is to up your integers from 0 to someBigInt
This will give the animator more numbers to work with.
ObjectAnimator progressAnimator = ObjectAnimator.ofInt(mProgressBar, "progress", 10000, 0);
The other option is to use ofFloat
which does the same thing as ofInt
but uses floating points instead of integers.
ObjectAnimator progressAnimator = ObjectAnimator.ofFloat(mProgressBar, "progress", 100.0, 0.0);
You can not use the ofFloat
because the ProgressBar's progress attribute doesn't accept float values, only integer ones. That is why your ProgressBar stopped progressing after going with that solution.
As the others have said it, the correct way to do what you want is to set android:max
to some big integer.
Sorry for reviving the thread but I feel like this had to be said.