2011-10-14 41 views
0
public class AndroidAnim extends Activity { 
/** Called when the activity is first created. */ 
boolean b=false; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    final ImageView imageView1 = (ImageView) findViewById(R.id.ImageView1); 
    final ImageView imageView2 = (ImageView) findViewById(R.id.ImageView2); 
    final AnimationDrawable myAnimation1; 

    imageView1.setBackgroundResource(R.drawable.loadinganim); 
    imageView2.setBackgroundResource(R.drawable.loadinganim); 

    myAnimation1 = (AnimationDrawable) imageView1.getBackground(); 

    imageView2.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      for(int i=0;i<20;i++){ 
      myAnimation1.start(); 
      imageView2.startAnimation(AnimationUtils.loadAnimation(getBaseContext(), R.anim.effect_in)); 
      } 
         } 
    }); 

}} 我 使用此代码试图招2 ImageView的。更清楚我希望当我点击屏幕时,一个接一个地移动ImageView(第一次移动imageView1,之后必须移动imageView2) 对不起,我的英文。如何移动的ImageView

+0

检查http://techdroid.kbeanie.com/2010/04/simple-drag-n-drop-on-android.html – milind

回答

0

也许AnimationListener可以帮你吗?

实现:

implements SurfaceHolder.Callback, AnimationListener { 

设置动画:

Animation effectIn; 
// in onCreate() 
effectIn = AnimationUtils.loadAnimation(this, R.anim.effect_in); 
effectIn.setAnimationListener(this); 

当一个动画结束,你触发其他:

@Override 
public void onAnimationEnd(Animation animation) { 
    if(animation == effectIn){ 
     // start effectOut or whatever. 
    } 

,如果你想动画留/停止他们结束的方式,使用这个:

effectIn.setFillAfter(true); 

或者在XML声明它:

android:fillEnabled="true" 
android:fillAfter="true" 

希望这有助于!