Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android imageButton在动画结束时闪烁_Android_Animation_Button - Fatal编程技术网

Android imageButton在动画结束时闪烁

Android imageButton在动画结束时闪烁,android,animation,button,Android,Animation,Button,我正在试着做一个可以移动的按钮。在动画结束之前,一切正常。发生的情况是,按钮消失,收割者非常快 这是我的密码: resetLayout = (RelativeLayout) findViewById(R.id.reset_layout); resetButton = (Button) findViewById(R.id.reset_button); resetLayout.setOnTouchListener(new OnTouchListener() { @O

我正在试着做一个可以移动的按钮。在动画结束之前,一切正常。发生的情况是,按钮消失,收割者非常快

这是我的密码:

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
,我正在更改按钮参数。因此,动画将完全停止。但是你可以看到它发生的瞬间

为什么会这样?我怎样才能修复它

谢谢

试试添加这个

TAnimation.setFillBefore(true);
到动画对象。

您可以尝试

TAnimation.setFillAfter(true); 
我想那会解决你的问题