我正在尝试使用xml动画和计时器为启动画面设置动画..我希望一个图像反弹,然后在另一个图像之后跟随我的最后一个图像
问题是当我在Timer中使用 runOnUiThread 后发生以下事情:
这里是Splash.java
public class Splash extends Activity implements AnimationListener {
LinearLayout li ;
ImageView s,e,c,r,e2,t;
// Animation
Animation animBounce;
// protected static final int TIMER_RUNTIME = 5000; // in ms --> 10s
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash2);
// load the animation
animBounce = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.bounce);
// set animation listener
animBounce.setAnimationListener(this);
s=(ImageView)findViewById(R.id.imgs);
e=(ImageView)findViewById(R.id.imge);
c=(ImageView)findViewById(R.id.imgc);
r=(ImageView)findViewById(R.id.imgr);
e2=(ImageView)findViewById(R.id.imge2);
t=(ImageView)findViewById(R.id.imgt);
//Start Animation
TimerTask animS = new TimerTask(){public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
s.setVisibility(View.VISIBLE);
s.startAnimation(animBounce);
}
});
}
};
TimerTask animE = new TimerTask(){public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
e2.setVisibility(View.VISIBLE);
e2.startAnimation(animBounce);
}
});
}
};
TimerTask animC = new TimerTask(){public void run() {
c.setVisibility(View.VISIBLE);
c.startAnimation(animBounce);
}
};
TimerTask animR = new TimerTask(){public void run() {
r.setVisibility(View.VISIBLE);
r.startAnimation(animBounce);
}
};
TimerTask animE2 = new TimerTask(){public void run() {
e2.setVisibility(View.VISIBLE);
e2.startAnimation(animBounce);
}
};
TimerTask animT = new TimerTask(){public void run() {
t.setVisibility(View.VISIBLE);
t.startAnimation(animBounce);
}
};
TimerTask task = new TimerTask(){public void run() {
Intent it=new Intent(Splash.this,TrippleDesDecrypt.class);
startActivity(it);
finish();
}
};
Timer tmrS=new Timer();
Timer tmrE=new Timer();
tmrS.schedule(animS, 1000);
tmrE.schedule(animE, 1900);
//t.schedule(task, 5*1000);
}
答案 0 :(得分:0)
谢谢大家回答这里是为我工作的代码
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for fade in animation
if (animation == animBounce1) {
e2.setVisibility(View.VISIBLE);
e2.startAnimation(animBounce2);
}
if (animation == animBounce2) {
c.setVisibility(View.VISIBLE);
c.startAnimation(animBounce3);
}
if (animation == animBounce3) {
r.setVisibility(View.VISIBLE);
r.startAnimation(animBounce4);
}
if (animation == animBounce4) {
e.setVisibility(View.VISIBLE);
e.startAnimation(animBounce5);
}
if (animation == animBounce5) {
t.setVisibility(View.VISIBLE);
t.startAnimation(animBounce6);
}
}