2012-11-12 64 views
0

我很驚訝地發現,在Android動畫方面有這麼幾個例子。我已經找到了動畫演示,但它們只提供了一小部分你可能想要實現的內容。如何圍繞中心軸旋轉一個形狀

對於我的具體情況,我只是試圖圍繞一箇中心點設置動畫形狀。我可以,你可以用下面的演示中看到的值傳遞:

ObjectAnimator.ofObject(
     ballHolder 
    , "name" 
    , new XYEvaluator() 
    , position1, position2, position3, position4, positionEtc); 

但我怎麼能在所有的值傳遞了一個圈?我相信你不會這樣做(如上面的例子)。

也許我應該以不同的方式做到這一點?任何幫助將非常感激。

回答

1

試試這個代碼,並將其調整需要:

爲了實現旋轉動畫,您可以在XML定義動畫: 下創建/ RE的動畫xml文件/被叫動畫文件夾:rotate_around_center_point.xml

<?xml version="1.0" encoding="utf-8"?> 
    <set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <rotate android:toDegrees="360" 
    android:duration="700" 
    android:pivotX="205"  
    android:pivotY="180" 
    android:interpolator="@android:anim/linear_interpolator"/> 
    </set> 

應用動畫查看:讓說,它旋轉圖像:

 ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage); 
    Animation animation = AnimationUtils.loadAnimation(this, 
    R.anim.rotate_around_center_point); animationTarget.startAnimation(animation); 

OR

在Java代碼中動態創建動畫:

Animation newAnimation = new RotateAnimation(0, 360, 205, 180); 
newAnimation.setDuration(700); 
animationTarget.startAnimation(newAnimation); 

希望這有助於。