Android imageButton在动画结束时闪烁
我正在试着做一个可以移动的按钮。在动画结束之前,一切正常。发生的情况是,按钮消失,收割者非常快 这是我的密码:Android imageButton在动画结束时闪烁,android,animation,button,Android,Animation,Button,我正在试着做一个可以移动的按钮。在动画结束之前,一切正常。发生的情况是,按钮消失,收割者非常快 这是我的密码: resetLayout = (RelativeLayout) findViewById(R.id.reset_layout); resetButton = (Button) findViewById(R.id.reset_button); resetLayout.setOnTouchListener(new OnTouchListener() { @O
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
,我正在更改按钮参数。因此,动画将完全停止。但是你可以看到它发生的瞬间
为什么会这样?我怎样才能修复它
谢谢 试试添加这个
TAnimation.setFillBefore(true);
到动画对象。您可以尝试
TAnimation.setFillAfter(true);
我想那会解决你的问题