2011-08-25 81 views
2
Android moving Image one point (0,0) to another point (30,400). using animation or normal 

looping condition. 

請告訴我一些想法...機器人:一個點移動圖片到另一點

+1

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html –

+1

嘿,這是使用多個圖像。但我只想使用一個圖像將一個點移動到另一個點。 – Jeeva

+0

**你需要這個** [http://www.twintechs.com/blog/?p=35](http://www.twintechs.com/blog/?p=35) –

回答

1

通過使用翻譯動畫,你可以做到這一點。 其中內翻譯的動畫X座標是原來的位置減去目標同樣是Y座標爲例

public TranslateAnimation(x1,X,y1,Y); 
    where X=0-30, Y=0-400; 

或者你也可以直接使用XML翻譯animation.place這個XML /res/anim/translate.translate XML文件中如下 -

<set xmlns:android="schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator"> 
     <translate android:fromXDelta="-30" android:fromYDelta="-400" 
     android:duration="700" /> 
    </set> 

現在,在您的活動

  Animation anim1 =AnimationUtils.loadAnimation(this,R.anim.translate); 
      yourImage.startAnimation(anim1); 
2

您可以使用翻譯阿尼馬特實現這一目標離子在android中。

TranslateAnimation animation = new TranslateAnimation(220, 80, 300, 80); //(float From X,To X, From Y, To Y) 
     animation.setDuration(1000); 
     animation.setFillAfter(false); 
     animation.setAnimationListener(new MyAnimationListener()); 

下面是實現AnimationListener接口的類。

private class MyAnimationListener implements Animation.AnimationListener { 

     @Override 
     public void onAnimationEnd(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
     } 

     @Override 
     public void onAnimationStart(Animation animation) { 
     } 

    } 

Atlast設置動畫的視圖,

view.setAnimation(animation); 
相關問題