圆形进度条(对一个倒数计时器) [英] Circular Progress Bar ( for a countdown timer )
问题描述
好了,所以我有15秒的倒计时定时器,工作完全正常,我想使该定时器自定义圆形进度条。
Ok so I have a countdown timer of 15 seconds that works perfectly fine and I'd like to make a custom circular progress bar for that timer.
我想创建一个完整的圆,获取馅饼(圈子)的切片取出作为计时器出现故障,直到不再有一个圆。
I want to create a full circle that gets "slices of the pie (circle)" taken out as the timer goes down until there is no longer a circle.
我preFER使自己的形状不是使用pre-制作图像,因为我想质量好上的任何电话。我怎么会去吗?谢谢!
I'd prefer to make the shapes myself than use pre-made images because I'd like the quality to be good on any phone. How would I go about this? Thanks!
推荐答案
我觉得这个例子很好:的http://mrigaen.blogspot.it/2013/12/create-circular-progress-bar-in-android.html
I found this example very good: http://mrigaen.blogspot.it/2013/12/create-circular-progress-bar-in-android.html
所以,我以这种方式创建我的进度条
So I created my progress bar in this way
<ProgressBar
android:id="@+id/barTimer"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:progressDrawable="@drawable/circular_progress_bar" />
然后,我做了一个功能,倒计时其中:
Then I made a function for the countdown where:
private void startTimer(final int minuti) {
countDownTimer = new CountDownTimer(60 * minuti * 1000, 500) {
// 500 means, onTick function will be called at every 500 milliseconds
@Override
public void onTick(long leftTimeInMilliseconds) {
long seconds = leftTimeInMilliseconds / 1000;
int barVal= (barMax) - ((int)(seconds/60*100)+(int)(seconds%60));
barTimer.setProgress(barVal);
textTimer.setText(String.format("%02d", seconds/60) + ":" + String.format("%02d", seconds%60));
// format the textview to show the easily readable format
}
@Override
public void onFinish() {
if(textTimer.getText().equals("00:00")){
textTimer.setText("STOP");
}
else{
textTimer.setText("2:00");
}
}
}.start();
}
这篇关于圆形进度条(对一个倒数计时器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!