我有2animation,我想要第一个,我的背景显示第一个动画,当第一个动画完成,然后我的4个按钮显示第二个动画。背景和按钮在一个XML文件中。我希望在运行动画时,onTouch()方法不起作用。
我搜索并说使用AnimationListener,但我不能使用它!
这是我的代码,请阅读并帮助我
public class Splash extends Activity {
Animation animation1;
Animation animation2;
Animation animation3;
ImageView image;
ImageButton circleProduct;
ImageButton circleIntroduce;
ImageButton circleMore;
ImageButton circleContact;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
animation1=AnimationUtils.loadAnimation(this, R.anim.bounce);
animation1.setAnimationListener(this);
animation2=AnimationUtils.loadAnimation(this, R.anim.push_left_out);
animation2.setAnimationListener(this);
animation3=AnimationUtils.loadAnimation(this, R.anim.push_left_out);
animation3.setAnimationListener(this);
image=(ImageView)findViewById(R.id.img);
image.startAnimation(animation1);
circleProduct=(ImageButton)findViewById(R.id.btnCircleProduct);
circleIntroduce=(ImageButton)findViewById(R.id.btnCircleIntroduce);
circleMore=(ImageButton)findViewById(R.id.btnCircleMore);
circleContact=(ImageButton)findViewById(R.id.btnCircleContact);
circleProduct.setVisibility(View.VISIBLE);
circleProduct.startAnimation(animation2);
circleContact.setVisibility(View.VISIBLE);
circleContact.startAnimation(animation2);
circleIntroduce.setVisibility(View.VISIBLE);
circleIntroduce.startAnimation(animation3);
circleMore.setVisibility(View.VISIBLE);
circleMore.startAnimation(animation3);
image.setOnTouchListener(onTouchListener);
circleProduct.setOnClickListener(onClickListener);
}
private OnTouchListener onTouchListener=new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.i("clicked", "on the Splas");
Intent intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
//finish();
return false;
}
};
private OnClickListener onClickListener=new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("circuleProduct", "clicked");
Intent intent=new Intent(Splash.this,Product.class);
startActivity(intent);
}
};
}
由于
答案 0 :(得分:0)
只需将animationListner添加到第一个动画中,然后在其onAnimationEnd方法中启动第二个动画
尝试以下代码
删除其他动画列表
animation1.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
yourView.startAnimation(animation2);
}
});
希望它会对你有所帮助。