Android 一个线程上的按钮动画和另一个线程中的工作

Android 一个线程上的按钮动画和另一个线程中的工作,android,multithreading,runnable,Android,Multithreading,Runnable,我认为我的问题是非常基本的,但我是android新手,所以只需要这个解决方案。 我有20个按钮,它们都在屏幕上设置动画(平移和缩放)。我想创建一个新的线程,并在那里做动画。这些按钮上有图像,代码在UI线程中运行良好,但有时我会收到一条消息和异常,即应用程序可能在其主线程上做了太多的工作。 请帮忙 多谢各位 这是我的onCreate,我想在其中在线程内制作动画:- protected void onCreate(Bundle savedInstanceState) { super.

我认为我的问题是非常基本的,但我是android新手,所以只需要这个解决方案。 我有20个按钮,它们都在屏幕上设置动画(平移和缩放)。我想创建一个新的线程,并在那里做动画。这些按钮上有图像,代码在UI线程中运行良好,但有时我会收到一条消息和异常,即应用程序可能在其主线程上做了太多的工作。 请帮忙 多谢各位

这是我的onCreate,我想在其中在线程内制作动画:-

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    playerName=getSharedPreferences(WelcomeActivity.Player_Name,0);
    gameMode= getSharedPreferences("game_mode", 0);

    setContentView(R.layout.activity_dragonland);       
    shendron=(ImageView)findViewById(R.id.shendron);
    glaedr=(ImageView)findViewById(R.id.glaedr);
    saphira=(ImageView)findViewById(R.id.saphira);
    brownlay=(ImageView)findViewById(R.id.brownlay);
    chrysophylax=(ImageView)findViewById(R.id.chrysophylax);
    tempest=(ImageView)findViewById(R.id.tempest);
    thrisorn=(ImageView)findViewById(R.id.thrisorn);
    ruth=(ImageView)findViewById(R.id.ruth);
    grifoka=(ImageView)findViewById(R.id.grifoka);
    horrid=(ImageView)findViewById(R.id.horrid);
    brownmean=(ImageView)findViewById(R.id.brownmean);
    firnen=(ImageView)findViewById(R.id.firnen);
    rhaegal=(ImageView)findViewById(R.id.rhaegal);
    mnementh=(ImageView)findViewById(R.id.mnementh);
    gorep=(ImageView)findViewById(R.id.gorep);
    rubela=(ImageView)findViewById(R.id.rubela);
    hotrika=(ImageView)findViewById(R.id.hotrika);
    drako=(ImageView)findViewById(R.id.drako);
    cadui=(ImageView)findViewById(R.id.cadui);      
    balerion=(ImageView)findViewById(R.id.balerion);


    dragon_zoom = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.dragon_zoom);
    dragon_zoom.setStartOffset(1500);
    down_right = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.down_right); 
    up_right = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.up_right); 
    seq_down= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequential_down);
    seq_up= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequential_up);
    seq_right= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequntial_right);
    seq_left= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequential_left);


    shendron.startAnimation(dragon_zoom);
    glaedr.startAnimation(seq_down);
    saphira.startAnimation(down_right);
    brownlay.startAnimation(seq_up);
    chrysophylax.startAnimation(seq_right);
    tempest.startAnimation(up_right);
    thrisorn.startAnimation(dragon_zoom);
    ruth.startAnimation(down_right);
    grifoka.startAnimation(down_right);
    horrid.startAnimation(dragon_zoom);
    brownmean.startAnimation(dragon_zoom);
    firnen.startAnimation(dragon_zoom);
    rhaegal.startAnimation(seq_right);
    mnementh.startAnimation(up_right);
    gorep.startAnimation(seq_left);
    rubela.startAnimation(seq_left);
    hotrika.startAnimation(seq_left);
    drako.startAnimation(seq_left);
    cadui.startAnimation(dragon_zoom);
    balerion.startAnimation(up_right);

}

您可以使用以下内容:

Thread thread = new Thread() 
{ 
 @Override 
 public void run() { 
    try { 
            Animation ranim = (Animation) AnimationUtils.loadAnimation(getBaseContext(), 
            R.anim.rotation); 
            buttonRotate.setAnimation(ranim); 
    } catch (InterruptedException e) { 
        e.printStackTrace(); 
    } 
 } 
}; 

thread.start();