0
好的,我从https://github.com/hongyangAndroid/Android-CircleMenu得到了以下代码。在这里,从打印轨迹中,我发现构造函数只被调用一次,而run()方法被递归调用,直到某些条件。Android:view的postDelayed(runnable,milliSeconds)如何与递归运行?
我的问题是,为什么只有run()方法递归调用postDelayed(),为什么不是构造函数?以及变角anglePerSecond如何保留该值?我想了解它的流程。谢谢。
//Automatic scrolling tasks
private class AutoFlingRunnable implements Runnable{
private float anglePerSecond;
public AutoFlingRunnable(float velocity){
this.anglePerSecond = velocity;
}
public void run(){
if((int)Math.abs(anglePerSecond) < 20){
isFling = false;
return;
}
isFling = true;
//anglePerSecond/30 in order to avoid rolling too fast
mStartAngle += (anglePerSecond/30);
//Gradually reduce this value
anglePerSecond /= 1.0666F;
postDelayed(this, 30);
//gradually reduce this value
requestLayout(); //re-layout views
}
}