gpt4 book ai didi

android - TranslateAnimation - 动画启动时图像消失

转载 作者:行者123 更新时间:2023-11-29 02:09:41 26 4
gpt4 key购买 nike

我尝试在 xml 文件中定义动画,但它没有提供足够的灵 active 。关于如何使它在代码中工作的任何想法。

我的图像消失,然后在动画开始时重新出现。本质上,当我抬起手指时,我需要图像以慢速滑动的方式移回其原始位置。由于某种原因,这没有发生。

Java代码:

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);
}
}

如果能得到任何帮助,我将不胜感激。

最佳答案

I want to be able to change the fromXdelta in my code itself.

你为什么不使用 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

关于android - TranslateAnimation - 动画启动时图像消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8195191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com