点击按钮停止动画

时间:2012-03-22 10:15:08

标签: java android

我在imageview上设置动画

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        i=(ImageView)findViewById(R.id.imageView1);
        d=(Button)findViewById(R.id.button1);
        a=new AnimationSet(false);
        ScaleAnimation s=new ScaleAnimation(0, 2, 0, 2);
        TranslateAnimation t=new TranslateAnimation(0, 100, 0, 0);

        a.addAnimation(s);
        a.addAnimation(t);
        a.setRepeatCount(0); 
        a.setDuration(500);     
        a.setFillAfter(false);

        a.setInterpolator(new AccelerateDecelerateInterpolator()); i.clearAnimation();

        d.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                i.clearAnimation();

            }
        });

        i.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub

                i.startAnimation(a);
                System.out.println("OnTouch called>>>>>>>>>>>");
                return false;
            }
        });
    }
}

现在的问题是停止动画并恢复按钮单击上的先前状态,直到图像应该保留,因为它设置为动画。 我

1 个答案:

答案 0 :(得分:2)

您好,请尝试添加此代码

        public void onClick(View v) {   
            // TODO Auto-generated method stub   
            i.clearAnimation();  
            a.cancel();  
            a.reset();  
        }
相关问题