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

标签 java android

在使用 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/

相关文章:

java - 数组初始化

php - App Inventor/PHP 应用程序停止在 Note 4 上运行

android - 自定义信息窗口中的阴影

android - java.lang.IllegalArgumentException : southern latitude exceeds northern latitude (23. 029011581089936 > 23.0060917)

java - Android:当我尝试从网站检索信息时,为什么我的 Android 应用程序显示空布局然后崩溃?

java - java中如何从乱七八糟的字符串中抓取文本?

java - 使用 LWJGL 生成浮雕渲染?

android - 自定义小部件中使用的自定义 XML 属性

android - Android 中的捕获请求和捕获 session

java - 方法 : com. foo.D.doSomething() 的签名不适用于参数类型 : (com. foo.C)