如何在两个功能之间提供时间差距?
public void onClick(View v) {
r1.startAnimation(slide_up);
Intent i = new Intent(Main_page.this, MainActivity.class);
startActivity(i);
}
答案 0 :(得分:0)
为动画添加AnimationListener
并在OnAnimationEnd()
看看这个https://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
答案 1 :(得分:0)
您可以使用Handler
延迟
public void onClick(View v) {
r1.startAnimation(slide_up);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Main_page.this, MainActivity.class);
startActivity(i);
}
}, 3000); // times in milliseconds
}
第二种方式使用Animation.AnimationListener
示例代码
slideUpAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent i = new Intent(Main_page.this, MainActivity.class);
startActivity(i);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
第三种方式
slideUpAnimation.withEndAction(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Main_page.this, MainActivity.class);
startActivity(i);
}
});
答案 2 :(得分:0)
试试这个
slide_up.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
Intent i = new Intent(Main_page.this, MainActivity.class);
startActivity(i);
}
});