gpt4 book ai didi

java - 动画停止后在 MotionEvent 和 Dialog 中使用

转载 作者:行者123 更新时间:2023-12-01 09:36:29 25 4
gpt4 key购买 nike

在使用 Dialog View 处理 MotionEvent 时,了解图像是否完全停止旋转的最佳方法是什么?

@Override
public boolean onTouchEvent(MotionEvent event)
{
ImageView iv= (ImageView)findViewById (R.id.animatedImage);
Dialog dialog = new Dialog (Player3AccessActivity.this);
dialog.setContentView(R.layout.custom);

switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
start =1000;
case MotionEvent.ACTION_MOVE:
start= start +250;
case MotionEvent.ACTION_UP:
Random random=new Random();
int toDegrees= random.nextInt(start +1000);

iv.animate()
.rotation(toDegrees)
.setInterpolator (new DecelerateInterpolator())
.setDuration(1000);
dialog.show();
break;
}
return(true);
}

最佳答案

动态创建一个动画对象,如下所示:

RotateAnimation r = new RotateAnimation(0f, -90f,200,200);
r.setStartOffset(1000);
r.setDuration(1000);
r.setFillAfter(true);
r.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
//
//Execute your code.(SHOW DIALOG)
//

System.out.println("DONE");
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});

然后像这样开始动画:

     //
//START ANIMATION
//

yourObjectToRotate.startAnimation(r);

您在 onAnimationEnd() 中提供的代码将在旋转动画完成时执行。

关于java - 动画停止后在 MotionEvent 和 Dialog 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38863639/

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