2011-10-14 52 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" 

希望這有助於!