我有一个"再次播放"按钮和" home"按钮。游戏结束时动画再次按钮已经动画化。代码如下
private void playagain(){
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
final Button btn = (Button) findViewById(R.id.playagain);
btn.setVisibility(View.VISIBLE);
btn.bringToFront();
btn.startAnimation(animation);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
view.clearAnimation();
btn.setVisibility(View.INVISIBLE);
findViewById(R.id.home).performClick();
}
});
}
它动画按钮并停止动画并调出主屏幕,但是如果单击主页按钮,那么我还希望再次播放按钮变为不可见并清除动画。
v.clearAnimation();在homebutton的onclick方法中没有清理动画。我该如何解决这个问题?
答案 0 :(得分:0)
您可以截取主页按钮上的点击并采取相应措施。
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
// clear animation here
}
return super.onKeyDown(keyCode, event);
}
希望它有所帮助。