当我执行我的应用程序时,我通过代码准备了一些动画:
public class MainActivity extends ActionBarActivity{
private Animation buscarAnimation2 = null;
private Animation buscarAnimation3 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout RL=(RelativeLayout)findViewById(R.id.RelativeLayout1);
buscarAnimation2 = AnimationUtils.loadAnimation(this, R.anim.boton2);
buscarAnimation3 = AnimationUtils.loadAnimation(this, R.anim.boton1);
RL.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
TextView t1=(TextView)findViewById(R.id.text_trad);
TextView t2=(TextView)findViewById(R.id.text_rell);
TextView t3=(TextView)findViewById(R.id.text_cub);
TextView t4=(TextView)findViewById(R.id.text_busq);
t1.setText(getString(R.string.main_trad));
t2.setText(getString(R.string.main_rell));
t3.setText(getString(R.string.main_cub));
t4.setText(getString(R.string.main_busq));
ImageButton b= (ImageButton)findViewById(R.id.imageButton1);
b.startAnimation(buscarAnimation2);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
ImageButton b2= (ImageButton)findViewById(R.id.ImageButton01);
b2.startAnimation(buscarAnimation3);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
ImageButton b3= (ImageButton)findViewById(R.id.ImageButton03);
b3.startAnimation(buscarAnimation2);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
ImageButton b4= (ImageButton)findViewById(R.id.ImageButton02);
b4.startAnimation(buscarAnimation3);
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
});
}
有时当我执行我的应用程序时,我不会查看动画,如果动画持续 4 秒,我会看到黑色主题,然后是动画的最后一秒或最后 2 秒。就像加载时遇到问题之类的...
那么我该怎么做才能避免这种情况,或者我做错了什么
编辑了代码。