imageButton在动画结束时闪烁

时间:2012-08-23 07:19:41

标签: android animation button

我正在尝试制作一个移动的按钮。一切正常,直到动画结束。发生的事情是按钮消失并且收割速度非常快。

这是我的代码:

resetLayout = (RelativeLayout) findViewById(R.id.reset_layout);
    resetButton = (Button) findViewById(R.id.reset_button);
    resetLayout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent mE) {

            delta = mE.getX();
            if (mE.getAction() == MotionEvent.ACTION_MOVE) {
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) resetButton
                        .getLayoutParams();
                params.setMargins((int) mE.getX() - 130, 0, 0, 0);
                resetButton.setLayoutParams(params);
            }

            if (mE.getAction() == MotionEvent.ACTION_UP) {
                final TranslateAnimation TAnimation=new TranslateAnimation(0, -mE.getX() + 50, 0, 0)   ;     
                TAnimation.setDuration(250);
                //TAnimation.setFillAfter(true);
                resetButton.startAnimation(TAnimation);
                TAnimation.setAnimationListener(new AnimationListener() {

                    public void onAnimationStart(Animation animation) {}
                    public void onAnimationRepeat(Animation animation) {}

                    public void onAnimationEnd(Animation animation) {
                        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) resetButton
                                .getLayoutParams();
                        params.setMargins(-80, 0, 0, 0);
                            resetButton.setLayoutParams(params);

                    }
                });

            //  Handler handler = new Handler();
            //  handler.postDelayed(delayRunnable, 2);
            }
            return true;
        }
    });

正如您在onAnimationEnd所看到的,我正在更改按钮参数。所以,动画就会停止。但你实际上可以看到它发生的闪烁时刻。

为什么会这样,我该如何解决?

谢谢!

2 个答案:

答案 0 :(得分:0)

尝试添加此

TAnimation.setFillBefore(true);

到动画对象。

答案 1 :(得分:0)

你可以尝试给予

TAnimation.setFillAfter(true); 

我认为这将解决您的问题

相关问题