亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何鏈接 rotationAnimation?

如何鏈接 rotationAnimation?

鳳凰求蠱 2023-04-19 17:04:06
我想旋轉一個 ImageView。但我想從 0 旋轉到 45 到 -45,然后返回 0 來總結我的目標。我嘗試創建 4rotationAnimation并將它們與AnimatorSet.這是我的代碼:    rotate = new RotateAnimation(0, 45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);    rotate.setDuration(1000);    rotate.setInterpolator(new LinearInterpolator());    rotate1 = new RotateAnimation(45, -45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);    rotate1.setDuration(1000);    rotate1.setInterpolator(new LinearInterpolator());    rotate2 = new RotateAnimation(-45, 45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);    rotate2.setDuration(1000);    rotate2.setInterpolator(new LinearInterpolator());    rotate3 = new RotateAnimation(45, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);    rotate3.setDuration(1000);    rotate3.setInterpolator(new LinearInterpolator());    setAnim= new AnimationSet(true);    setAnim.addAnimation(rotate);    setAnim.addAnimation(rotate1);    setAnim.addAnimation(rotate2);    setAnim.addAnimation(rotate3);img.startAnimation(setAnim);目前圖像突然沒有旋轉到 45° 并返回到 0°。
查看完整描述

2 回答

?
青春有我

TA貢獻1784條經驗 獲得超8個贊

您可以使用AnimationListener


例子


yourFirstAnim.setAnimationListener(new AnimationListener() {


    @Override

    public void onAnimationStart(Animation animation) {

    }


    @Override

    public void onAnimationRepeat(Animation animation) {

    }


    @Override

    public void onAnimationEnd(Animation animation) {

      doYourNextAnim()

    }

  });

或者更簡單的方法,使用AnimatorSet()


AnimatorSet as = new AnimatorSet();

as.playSequentially(yourFirstAnim, 

                    yourSecondAnim,

                    ..,

                    ...);

as.setDuration(YOUR_DURATION);

as.start();

更新 為了避免回調地獄,我們可以使用StartDelay


imgAvatar1.animate()

        .alpha(1f)

        .setDuration(YOUR_DURATION)

        .start()


    imgAvatar2.animate()

        .alpha(1f)

        .setStartDelay(YOUR_DURATION * 1)

        .setDuration(YOUR_DURATION)

        .start() 


    imgAvatar3.animate()

        .alpha(1f)

        .setStartDelay(YOUR_DURATION * 2)

        .setDuration(YOUR_DURATION)

        .start() 


查看完整回答
反對 回復 2023-04-19
?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

您正在使用您的AnimationSet().

問題可能出在參數上fillAfter

setFillAfter(true)在你的動畫上使用rotate,所以動畫參數在動畫之后應用。


查看完整回答
反對 回復 2023-04-19
  • 2 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號