簡體   English   中英

android如何使用RotateAnimation旋轉圖像兩次

[英]android how to rotate an image twice using RotateAnimation

我正在使用旋轉動畫將圖像旋轉到某種程度,並且在同一屏幕上,我希望用戶通過單擊按鈕將同一圖像從上一個位置旋轉到下一個位置,但是旋轉沒有任何反應。

///inside oncreate 

RotateAnimation rotate = new RotateAnimation(0, rotateSpeed,
                        Animation.RELATIVE_TO_SELF, 0.9f,
                        Animation.RELATIVE_TO_SELF, 0.5f);

                rotate.setDuration(4000);
                rotate.setFillAfter(true);
                imv.setAnimation(rotate);

///inside button click

RotateAnimation rotate = new RotateAnimation(start, start+end,
                Animation.RELATIVE_TO_SELF, 0.9f,
                Animation.RELATIVE_TO_SELF, 0.5f);

        rotate.setDuration(2000);
        rotate.setFillAfter(true);
        imv.setAnimation(rotate);

將您的視圖和旋轉值傳遞給此方法。 希望這能解決您的問題。

public void rotateView(final View v, final int rotation) {

    v.animate().setDuration(250).rotation(rotation).setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
        }
    });
}
RotateAnimation rotate = new RotateAnimation(0, 360,
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
        0.5f);

rotate.setDuration(4000);
rotate.setRepeatCount(-1); // here you can set repeatcoount
yourView.setAnimation(rotate)

希望對您有幫助。

干杯!

哦,我只是在應用新的旋轉動畫之前清除已經應用的旋轉動畫。

view.clearAnimation();

暫無
暫無

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

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