我正在尝试制作一个可以移动的按钮。一切正常,直到动画结束。发生的情况是按钮消失并且收割速度非常快。
这是我的代码:
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,我正在更改按钮参数。所以,这将是动画停止。但你实际上可以看到它发生的瞬间。
为什么会这样,我该如何解决?
谢谢!