0

我有 2 个动画,我想要第一个,我的背景显示第一个动画,当第一个动画完成时,我的 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);
    }

};

 }

谢谢

4

1 回答 1

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);
        }
    });

希望它会帮助你。

于 2013-09-25T16:32:39.043 回答