Android动画师如何使用动画

Android how to use animation after an animator

谁能帮我写代码?我想做的是,当 imageView 被触摸时,它会 运行 animator 并将视图移动到屏幕中央。动画师完成后,imageView 将另一个 onTouch 设置为 运行 从 0.0 - 1 缩放的动画。0.But 动画不会从视图的新位置开始,而是从以前的位置开始的观点。

private void animation() {
    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            imageView.animate().translationY(height/2).setDuration(1000).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    imageView.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            ScaleAnimation scale = new ScaleAnimation(0,1,0,1);
                            scale.setDuration(1000);
                            imageView.startAnimation(scale);
                            return true;
                        }
                    });
                }
            }).start();
            return false;
        }
    });
}

link 是我从代码中得到的 http://sendvid.com/0vbtkhi7

下面的link是我想用动画得到的结果

http://sendvid.com/68q53bh6

这是因为您正在使用 ViewAnimation。它只是动画视图而不是对象本身,因此对象坐标保持不变,当您重新加载新动画时,它以不变的 X 和 Y 开始。 您应该使用 Android Property Animation API.

更简单,您的问题将得到解决。

啊,我基本上找到了解决方案,我只需要更新数据透视表即可。

private void animation() {
    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            imageView.animate().translationY(height/2).setDuration(1000).start();
            imageView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,imageView.getWidth()/2,imageView.getY() + imageView.getHeight()/2);
                    scaleAnimation.setDuration(1000);
                    imageView.startAnimation(scaleAnimation);
                    return true;
                }
            });
            return false;
        }
    });
}

顺便说一句,感谢您回答我的问题