簡體   English   中英

Android如何在動畫師之后使用動畫

[英]Android how to use animation after an animator

誰能幫我提供我的代碼? 我想做的是當imageView被觸摸時它將運行動畫器並將視圖移動到屏幕的中心。 動畫師完成后,imageView將設置另一個onTouch來運行動畫以在0.0-1.0范圍內縮放。但是動畫將不會從視圖的新位置開始,而是從視圖的先前位置開始。

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

鏈接是我從代碼http://sendvid.com/0vbtkhi7獲得的

和下面的鏈接是我想通過使用動畫獲得的結果

http://sendvid.com/68q53bh6

這是因為您正在使用ViewAnimation。 它僅對View進行動畫處理,而不對對象本身進行動畫處理,因此對象坐標保持不變,並且當您重新加載新動畫時,它以不變的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;
        }
    });
}

順便說一句謝謝您回答我的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM