動くボタンを作ってみました。アニメーションが終了するまで、すべてが正常に機能しています。何が起こるかというと、ボタンが消えてリーパーが非常に速くなります。
これが私のコードです:
resetLayout = (RelativeLayout) findViewById(R.id.reset_layout);
resetButton = (Button) findViewById(R.id.reset_button);
resetLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent mE) {
delta = mE.getX();
if (mE.getAction() == MotionEvent.ACTION_MOVE) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) resetButton
.getLayoutParams();
params.setMargins((int) mE.getX() - 130, 0, 0, 0);
resetButton.setLayoutParams(params);
}
if (mE.getAction() == MotionEvent.ACTION_UP) {
final TranslateAnimation TAnimation=new TranslateAnimation(0, -mE.getX() + 50, 0, 0) ;
TAnimation.setDuration(250);
//TAnimation.setFillAfter(true);
resetButton.startAnimation(TAnimation);
TAnimation.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) resetButton
.getLayoutParams();
params.setMargins(-80, 0, 0, 0);
resetButton.setLayoutParams(params);
}
});
// Handler handler = new Handler();
// handler.postDelayed(delayRunnable, 2);
}
return true;
}
});
でわかるようにonAnimationEnd
、ボタンのパラメーターを変更しています。だから、それはまさにアニメーションが停止したことになります。しかし、実際にそれが起こる点滅の瞬間を見ることができます。
それはなぜですか、どうすれば修正できますか?
ありがとう!