Java 连续向前和向后过渡?
我正在尝试为紧急情况制定一项活动。我希望背景必须根据转换xml不断变化。过渡色介于黑色和红色之间。我实现了一个计数器,当它结束时,我再次启动它以无限地使用它 这是我的密码: 但是我无法从我的代码中得到我想要的。它进行正向转换,然后进行反向转换。它会这样做3或4次,在那个时候发生了一些事情,连续性中断。它以同样的方式再次开始循环Java 连续向前和向后过渡?,java,android,transition,infinite-loop,freeze,Java,Android,Transition,Infinite Loop,Freeze,我正在尝试为紧急情况制定一项活动。我希望背景必须根据转换xml不断变化。过渡色介于黑色和红色之间。我实现了一个计数器,当它结束时,我再次启动它以无限地使用它 这是我的密码: 但是我无法从我的代码中得到我想要的。它进行正向转换,然后进行反向转换。它会这样做3或4次,在那个时候发生了一些事情,连续性中断。它以同样的方式再次开始循环 欢迎提出任何建议或其他想法 事情发生了,可能是StackoverflowException@Kedarnath你能进一步解释StackoverflowException吗
欢迎提出任何建议或其他想法 事情发生了,可能是StackoverflowException@Kedarnath你能进一步解释StackoverflowException吗?我怎么能理解这就是例外呢?日志中没有任何异常。基本上,您所做的就是递归,这意味着一个方法再次调用self&再次调用self。每次调用它时,它都会为该方法创建一个内存块,当该内存块满时,代码停止工作,该阶段称为StackOverflowException
package com.example.transitionbetweencolors;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.Activity;
import android.graphics.drawable.TransitionDrawable;
import android.view.Menu;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
RelativeLayout relative_layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relative_layout = (RelativeLayout) findViewById(R.id.my_relative_layout);
relative_layout.setBackgroundResource(R.drawable.transition_colors);
final TransitionDrawable drawable = (TransitionDrawable) relative_layout.getBackground();
CountDownTimer x = new CountDownTimer(1000, 1000) {
public void onTick(long millisUntilFinished) {
drawable.startTransition(1000);
}
public void onFinish() {
// showNotification();
drawable.reverseTransition(1000);
start();// here, when your CountDownTimer has finished , we start it again :)
}
};
x.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}