簡體   English   中英

在動畫中使用5-6個線程是個好主意嗎?

[英]Is it a good idea to use 5-6 threads in an animation?

我一次使用5-6個線程顯示一個動畫,同時使用平移動畫和幀動畫。 這是一個好主意嗎? 最好的方法是什么? 我的代碼在下面給出。

Handler handler1 = new Handler();        
handler1.postDelayed(new Runnable() {
  public void run() {
    Animation animation = new TranslateAnimation(0 ,0 ,0 ,100 );
    animation.setDuration(800);
    ImageView rimg2 = (ImageView) findViewById(R.id.rainfall);
    animation.setRepeatCount(-1);
    rimg2.startAnimation(animation);

    Animation animation1 = new TranslateAnimation(-290, 290,0, -150);
    animation1.setDuration(35000);
    ImageView rimg = (ImageView) findViewById(R.id.cloud1);
    rimg.setVisibility(View.VISIBLE);
    animation1.setRepeatCount(-1);
    rimg.startAnimation(animation1);
  } 
},0);

Handler handler2 = new Handler();
handler2.postDelayed(new Runnable() {
  public void run() {
    Animation animation = new TranslateAnimation(0 ,0 ,0 ,100 );
    animation.setDuration(800);
    ImageView rimg3 = (ImageView) findViewById(R.id.drops);
    animation.setRepeatCount(-1);
    rimg3.startAnimation(animation);
    rimg3.setVisibility(View.VISIBLE);
  }
},1000);

Handler handler3 = new Handler();
handler3.postDelayed(new Runnable() {
  public void run() {
    Animation animation = new TranslateAnimation(0 ,0 ,-250 ,10 );
    animation.setDuration(800);
    ImageView rimg2 = (ImageView) findViewById(R.id.rainfall1);
    animation.setRepeatCount(-1);
    rimg2.startAnimation(animation);
    rimg2.setVisibility(View.VISIBLE);
    }
},5000);

Handler handler4 = new Handler();
handler4.postDelayed(new Runnable() {
  public void run() {
    Animation animation = new TranslateAnimation(0 ,0 ,-150 ,10 );
    animation.setDuration(800);
    ImageView rimg3 = (ImageView) findViewById(R.id.drops1);
    animation.setRepeatCount(-1);
    rimg3.startAnimation(animation);
    rimg3.setVisibility(View.VISIBLE);
    }
},10000);

Handler handler5 = new Handler();
handler5.postDelayed(new Runnable() {
  public void run() {
    Animation animation1 = new TranslateAnimation(-290, 290,0, -150);
    animation1.setDuration(35000);
    ImageView rimg = (ImageView) findViewById(R.id.cloud2);
    rimg.setVisibility(View.VISIBLE);
    animation1.setRepeatCount(-1);
    rimg.startAnimation(animation1);
  }
},15000);

除非代碼示例中未顯示原因,否則您無需發布Runnable即可運行這些動畫。 您可以從主UI線程開始動畫。 有關更多詳細信息,請在此處查看文檔:

http://developer.android.com/guide/topics/graphics/view-animation.html

和這里

http://developer.android.com/reference/android/view/animation/Animation.html

如果要錯開動畫的開始時間,也可以設置StartOffset。

如果要在動畫結束時執行某些操作,則可以使用Animation.setAnimationListener

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM