自定义进度条更新不流畅
Custom progress bar doesn't update smoothly
我正在尝试顺利地制作一个循环进度条 运行 但我没有结果。进度条应根据计时器值进行更新。
下面是我如何设置进度条的动画,
int progress = (int)(this.mCurrentTimerValue/1000);
this.mProgressBarAnimation = ObjectAnimator.ofInt(this.mProgressBar,"progress",progress);
this.mProgressBarAnimation.setDuration(this.mCurrentTimerValue);
this.mProgressBarAnimation.setInterpolator( new LinearInterpolator());
其中 this.mCurrentTimerValue 是以毫升为单位的时间。对于这个例子是 10000
这是结果,
我想顺利显示进度但是我不能。我尝试使用 ObjectAnimator.ofFloat 因为问题可能是我试图在整数空间中取得进展,但在那种情况下动画不起作用。
下面是我自定义进度条的方法,
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="@color/yellow"
android:endColor="@color/yellow"
android:startColor="@color/yellow"
android:type="sweep" />
</shape>
</rotate>
</item>
<item android:id="@android:id/secondaryProgress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="@color/green"
android:endColor="@color/green"
android:startColor="@color/green"
android:type="sweep" />
</shape>
</rotate>
</item>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="false"
android:progress="100"
android:progressDrawable="@drawable/custom_progress_bar" />
我阅读了这些问题,但对我没有帮助,
- question 1
- question 2
- question 3
如果有人需要针对这种情况的解决方案,this answer 帮助了我,但我承认我认为这不是最好的。
我正在尝试顺利地制作一个循环进度条 运行 但我没有结果。进度条应根据计时器值进行更新。
下面是我如何设置进度条的动画,
int progress = (int)(this.mCurrentTimerValue/1000);
this.mProgressBarAnimation = ObjectAnimator.ofInt(this.mProgressBar,"progress",progress);
this.mProgressBarAnimation.setDuration(this.mCurrentTimerValue);
this.mProgressBarAnimation.setInterpolator( new LinearInterpolator());
其中 this.mCurrentTimerValue 是以毫升为单位的时间。对于这个例子是 10000
这是结果,
我想顺利显示进度但是我不能。我尝试使用 ObjectAnimator.ofFloat 因为问题可能是我试图在整数空间中取得进展,但在那种情况下动画不起作用。
下面是我自定义进度条的方法,
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="@color/yellow"
android:endColor="@color/yellow"
android:startColor="@color/yellow"
android:type="sweep" />
</shape>
</rotate>
</item>
<item android:id="@android:id/secondaryProgress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="@color/green"
android:endColor="@color/green"
android:startColor="@color/green"
android:type="sweep" />
</shape>
</rotate>
</item>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="false"
android:progress="100"
android:progressDrawable="@drawable/custom_progress_bar" />
我阅读了这些问题,但对我没有帮助,
- question 1
- question 2
- question 3
如果有人需要针对这种情况的解决方案,this answer 帮助了我,但我承认我认为这不是最好的。