2014-01-17 30 views
0

我需要在我的項目中實現動畫, 將視圖從左下角移動到右下角。同時另一個視圖需要從屏幕的上方到中心,如何可以我使用Object動畫實現它。Android中的對象動畫

+1

看看這個:http://developer.android.com/training/animation/zoom.html –

回答

0

如果這就是你想要實現的全部(只是移動視圖),那麼你可以用幾行代碼來做到這一點,而不使用xmls。讓我們舉例說100像素向右移動一個按鈕。

// Get the view 
TranslateAnimation slideRight = new TranslateAnimation(0, 200f, 0, 0); 

// logoutButton is the view that is to be animated 
logoutButton.setAnimation(slideRight); 

// or 
logoutButton.startAnimation(slideRight); // to immediately start the animation 

參考TranslateAnimation

0

您可以創建動畫的XML文件,並加載它們對你的看法。 參考view animation。 動畫XML文件:

<set android:shareInterpolator="false"> 
    <scale 
     android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
     android:fromXScale="1.0" 
     android:toXScale="1.4" 
     android:fromYScale="1.0" 
     android:toYScale="0.6" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fillAfter="false" 
     android:duration="700" /> 
    <set android:interpolator="@android:anim/decelerate_interpolator"> 
     <scale 
      android:fromXScale="1.4" 
      android:toXScale="0.0" 
      android:fromYScale="0.6" 
      android:toYScale="0.0" 
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:startOffset="700" 
      android:duration="400" 
      android:fillBefore="false" /> 
     <rotate 
      android:fromDegrees="0" 
      android:toDegrees="-45" 
      android:toYScale="0.0" 
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:startOffset="700" 
      android:duration="400" /> 
    </set> 
</set> 

負載的動畫你的意見

ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage); 
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump); 
spaceshipImage.startAnimation(hyperspaceJumpAnimation);