我正在为自定义循环进度轮做。这里我需要的是,一旦进度轮完成百分之百的进步。然后,当我再次点击时,我需要在运行时更改进度颜色...
我从此链接下载了代码.. https://github.com/Todd-Davies/ProgressWheel
注意:我点击一个按钮,进度开始进行。进度条圈已经是一种颜色。在完成100%的进度后,我希望它再次启动,那个时候,我需要在运行时将颜色更改为红色...
我也试过这个链接..这个链接用于默认进度条。 但是,我正在使用自定义进度bar.thats为什么,我不能使用这种方法,如... http://myandroidsolutions.blogspot.in/2012/11/android-change-indeterminate-progress.html http://www.tiemenschut.com/how-to-customize-android-progress-bars/
任何人都可以帮我完成这项任务.. 谢谢前进......
我的代码: onCreate方法:
increment.setOnClickListener(new OnClickListener() {
@SuppressLint("WrongCall")
public void onClick(View v) {
Log.v("test", "-----increment button clicked--------");
if(!running) {
progress1 = (int) 370 ;
Thread s = new Thread(r);
s.start();
}
}
});
final Runnable r = new Runnable() {
@SuppressLint("WrongCall")
public void run() {
//Log.v("test", "----- thread called--------");
running = true;
//Log.v("test", "progress:"+progress);
//Log.v("test", "progress1:"+progress1);
progress2 = progress - progress1 ;
//progress = 360 , progress1 = uservalue
Log.v("test", "progress:"+progress);
Log.v("test", "progress1:"+progress1);
Log.v("test", "progress2 = progress - progress1:"+progress2);
//percentage = pw_two.incrementProgress();
// pw_two.setBarColor(Color.parseColor("#FF0000"));
while(progress2<360) {
percentage = pw_two.incrementProgress();
Log.v("test","percentage:"+percentage);
progress2++;
try {
Thread.sleep(15);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// here when crossing 360 above , then color change effect needed..
//why we using this function, when put ten minutes for break,
who taking more than ten minutes,,
// then that time itself, need to change color..
i finish that time calculation....
if(progress2 > 359) {
// here.. need to call this method two times.. then only, wheel will be refreshed......
//onPause_Reset_ProgressWheelOne();
onPause_Reset_ProgressWheelOne();
//break;
}
}
running = false;
}
};
public void onPause_Reset_ProgressWheelOne() {
Log.v("test", "onPause_Reset_ProgressWheelOne--------");
progress = 360;
pw_two.setRimColor(Color.parseColor("#fe854c")); //1988c4 //fe854c
pw_two.setBarColor(Color.RED);
//pw_two.resetCount();
pw_two.refreshWheel();
// progress = 0;
// pw_two.setProgress(0);
}
ProgressWheel.java CLass :
public void refreshWheel() {
setupPaints();
}
答案 0 :(得分:7)
在ProgressWheel.java
内(com.todddavies.components.progressbar.ProgressWheel),添加一个方法:
public void refreshTheWheel() {
setupPaints();
}
我点击一个按钮,进度开始进行。进度条圈已经是一种颜色。在完成100%的进度后,我希望它再次启动,那个时候,我需要将颜色更改为红色
当您需要更改颜色时:
// Progress is 100%
if (progress == 360) {
// Change the color
mProgressWheel.setBarColor(Color.RED);
// Refresh
mProgressWheel.refreshTheWheel();
// Reset progress
progress = 0;
mProgressWheel.setProgress(0);
// You can also use:
// mProgressWheel.resetCount();
}
注意:请确保允许编辑/添加到此库。
修改强>
查看以下更改是否可以获得所需的输出:
声明全局变量:
// `progress` isn't needed
// int progress = 360;
int progress1 = 0;
int progress2 = 0;
....
....
increment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.v("test", "-----increment button clicked--------");
if(!running) {
// I am not sure what you are using `progress1` for
// progress1 = (int) 370 ;
progress1 = 0;
progress2 = 0;
// reset `pw_two`
pw_two.resetCount();
Thread s = new Thread(r);
s.start();
}
}
});
现在,Runnable
:
final Runnable r = new Runnable() {
public void run() {
running = true;
// I could not figure out why you are using this
// Can you explain what this does?
// progress2 = progress - progress1 ;
while(progress2 < 361) {
pw_two.incrementProgress();
// Increment both `progress1` and `progress2`
progress2++;
progress1++;
try {
Thread.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Here, reset `progress2`, but not `progress1`
if (progress2 == 360) {
pw_two.setRimColor(Color.parseColor("#fe854c")); //1988c4 //fe854c
pw_two.setBarColor(Color.RED);
pw_two.refreshWheel();
progress2 = 0;
pw_two.setProgress(0);
// Log value of `progress1`
Log.v("Progress 1", "progress1 is " + progress1);
}
}
running = false;
}
};
您无需再调用其他方法。在progressValue = 360
,颜色会切换。如果我以某种方式误解了你想要实现的目标,你能用一些用例来解释吗?
答案 1 :(得分:1)
检查this示例,它有一个循环进度条,可在进度增加时更改颜色。