【问题标题】:Android Circle progress view show timer inside the circle instead of %Android Circle进度视图在圆圈内显示计时器而不是%
【发布时间】:2016-03-14 08:33:52
【问题描述】:
我正在使用这个很棒的库:lzyzsd/CircleProgress
我试图在圆心显示倒计时类型计时器:01:30 或 03:50 它是 mm:ss 但现在确定要使用什么属性。
我只能选择设置前缀和后缀,但不能设置实际文本。我有以秒为单位的倒数计时器的总时间,我也可以计算到分钟和秒,但是如何将其显示在中心?
如果我不设置前缀和后缀,则默认情况下为 0,我不想显示。
【问题讨论】:
标签:
android
mobile
timer
progress-bar
【解决方案1】:
不幸的是,似乎没有办法直接做到这一点。这是我会做的:
DonutProgress donutProgress = (DonutProgress) findViewById(R.id.aworkout_dp_totaltime);
donutProgress.setSuffixText(""); //removes the % in the end
donutProgress.setMax(90); //so if the countdown starts from 1min 30 sec
//hides the default text which in this case would be 90 at the start
donutProgress.setTextColor(Color.parseColor("#00000000")); //the color is transparent
在xml中,
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.github.lzyzsd.circleprogress.DonutProgress
android:id="@+id/dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/countdownTimerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
现在调整 donutprogress 的大小和 textview 的字体大小,使 textview 正确地适合 donutprogress 的中心。在 onTick 方法期间使用倒数计时器设置 textview 的值。在 onTick 期间,您还必须执行 donutProgress.setProgress(donutProgress.getProgress + 1);。因此你的计时器会改变,进度也会改变。注意进度是从0开始的。