我认为我的问题非常基本,但我是 android 新手,所以只需要这个解决方案。我有 20 个按钮,所有按钮都在屏幕上显示动画(平移和缩放)。我想创建一个新线程并在那里做动画。这些按钮上有图像,代码在 UI 线程中工作正常,但有时我收到 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);
}