我有一个包含圆形ProgressBar和一个显示倒计时的TextView的布局。如何在进度栏中显示计时器的当前进度?第一次显示时,进度条应该是满的,而计时器到时,进度条应该是空的。
private fun setProgressBar(timeToShow: Int) {
countDownTimer = object : CountDownTimer(
timeToShow * ONE_SECOND_INTERVAL,
ONE_SECOND_INTERVAL
) {
override fun onTick(millisUntilFinished: Long) {
question_time.text = (millisUntilFinished / ONE_SECOND_INTERVAL).toString()
//handleProgressBar
}
override fun onFinish() {
hideLayout()
}
}.start()
}
<ProgressBar
android:id="@+id/question_time_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?android:progressBarStyleHorizontal"
android:progressDrawable="@drawable/circle_progressbar"
/>
<TextView
android:id="@+id/question_time"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/test_color_light"
android:textStyle="bold"
tools:text="14" />
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="false">
<solid android:color="#DDD" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="true">
<gradient
android:endColor="@color/colorPrimary"
android:startColor="@color/colorAccent"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
您应该将最大进度设置为倒数开始的数字。例如,如果倒数从60开始。则应设置progressBar.setMax(60)
然后在每次倒数计时时,为进度条设置值,例如progressBar.setValue(59),然后是58,然后是57...。进度条将按照您想要的方式工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句