2014-02-26 120 views
0

我試圖讓文本視圖逐個放大/縮小4次。它只有一次,然後就死了。動畫不重複

public class MainActivity extends Activity implements AnimationListener { 
    Animation zoomin, zoomout; 
    TextView text; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     text = (TextView) findViewById(R.id.text); 
     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       for (int i = 0; i < 4; i++) { 
        zoomin = AnimationUtils.loadAnimation(MainActivity.this, 
          R.anim.zoomin); 
        zoomin.setAnimationListener(MainActivity.this); 
        zoomout = AnimationUtils.loadAnimation(MainActivity.this, 
          R.anim.zoomout); 
        text.setAnimation(zoomin); 
        text.setAnimation(zoomout); 

        text.startAnimation(zoomin); 
        try { 
         Thread.sleep(500); 
        } catch (InterruptedException e) { 
         e.printStackTrace(); 
        } 
       } 
      } 
     }); 
    } 
    @Override 
    public void onAnimationEnd(Animation animation) { 
     text.startAnimation(zoomout); 
    } 
} 

回答

1

變化

text.startAnimation(zoonout); 

text.startAnimation(zoomin); 

希望它可以幫助ü。祝你今天愉快。

+0

感謝您編輯答案sirko。 – baskar

+0

upvote for answer,謝謝baskar – Siddharth

+0

感謝喜歡Siddharth。我很高興該解決方案適合您。祝你今天愉快。 – baskar