給一個view新增旋轉動畫,並且停止後保持旋轉角度,恢復後可繼續旋轉
阿新 • • 發佈:2018-12-20
RotateAnimation這個動畫類 animation.setFillAfter(true);方法是在動畫自動停止後保持原位,而手動停止呼叫clearAnimation()後旋轉的控制元件會變成最開始的位置,想到的解決方 法是讓動畫旋轉30度 利用handle不斷的傳送訊息 當點選停止後取消傳送訊息,不是很好的解決辦法。
經過查詢資料發現 ObjectAnimator屬性動畫
ObjectAnimator animator = ObjectAnimator.ofFloat(im_scan, "rotation", 0f, 360.0f);
animator.setDuration(2000);
animator.setInterpolator(new LinearInterpolator());//不停頓
animator.setRepeatCount(-1);//設定動畫重複次數
animator.setRepeatMode(ValueAnimator.RESTART);//動畫重複模式
animator.start();//開始動畫
animator.pause();//暫停動畫
animator.resume();//恢復動畫
這幾個方法就能實現效果。