2013-09-14 3 views
0

Я думаю, что моя проблема очень проста, но я новичок в android, поэтому просто нужно это решение. У меня есть 20 кнопок, и все они оживляют (перевод и масштабирование) на экране. Я хочу создать новый поток и сделать анимацию там. Эти кнопки имеют изображения на них, код работает нормально в потоке пользовательского интерфейса, но иногда я получаю сообщение ANR и исключение, что приложение может слишком много работать над его основным потоком. Пожалуйста, помогите СпасибоКнопка анимации на одном потоке и работает в другом потоке

Это мой 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); 

} 

ответ

1

вы можете использовать что-то вроде этого:

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(); 
+0

это работало после удаления попробовать поймать... –

Смежные вопросы