2011-08-25 83 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); 
相关问题