我尝试在xml文件中定义动画,但它没有提供足够的灵活性。关于我如何在代码中使用它的任何想法。
我的图像消失,然后在动画开始时重新出现。基本上,当我抬起手指时,我需要将图像作为缓慢的滑动移回原来的位置。这不是出于某种原因。
Java CODE:
chargeButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
switch (event.getActionMasked()){
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
chargeButton.setLayoutParams(setPosition(x_cord, false));
break;
case MotionEvent.ACTION_UP:
int x_start = x_cord;
x_cord = 0;
slowMove(x_start, x_cord, false);
break;
default:
break;
}
return true;
}
});
}
public void slowMove(int x_start, int x_final, boolean pay)
{
Animation transAnimation = new TranslateAnimation(x_start, x_final, 0, 0);
transAnimation.setFillAfter(true);
transAnimation.setDuration(1000);
if (pay)
payButton.startAnimation(transAnimation);
else
{
chargeButton.clearAnimation();
chargeButton.startAnimation(transAnimation);
}
}
我真的很感激我能得到的任何帮助。
答案 0 :(得分:1)
我希望能够在我的代码中更改fromXdelta。
为什么不使用constructor本身?
public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
fromXDelta Change in X coordinate to apply at the start of the animation
toXDelta Change in X coordinate to apply at the end of the animation
fromYDelta Change in Y coordinate to apply at the start of the animation
toYDelta Change in Y coordinate to apply at the end of the animation