2012-03-22 93 views
0

我將動畫添加到imageview中,我希望保持動畫狀態,直到時間按鈕按下按鈕按下移動到前一個狀態 這裏是我的代碼,使用setFillAfter不要讓它恢復並設置爲false,它不停留在動畫狀態停止按鈕上的動畫點擊圖片

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     i=(ImageView)findViewById(R.id.imageView1); 
     d=(Button)findViewById(R.id.button1); 
     a=new AnimationSet(false); 
     ScaleAnimation s=new ScaleAnimation(0, 2, 0, 2); 
     TranslateAnimation t=new TranslateAnimation(0, 100, 0, 0); 

     a.addAnimation(s); 
     a.addAnimation(t); 
     a.setRepeatCount(0); 
     a.setDuration(500);  
     a.setFillAfter(false); 

     a.setInterpolator(new AccelerateDecelerateInterpolator()); i.clearAnimation(); 

     d.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

      i.clearAnimation(); 
      } 
     }); 

     i.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       // TODO Auto-generated method stub 

       i.startAnimation(a); 
       System.out.println("OnTouch called>>>>>>>>>>>"); 
       return false; 
      } 
     }); 
    } 

回答

1

更改重複模式無限

a.setRepeatMode(Animation.INFINITE); 

,並使用動畫監聽器,現在你可以啓動動畫並在ev時停止動畫呃你想要的。欲瞭解更多詳情。見This Details example