0

動くボタンを作ってみました。アニメーションが終了するまで、すべてが正常に機能しています。何が起こるかというと、ボタンが消えてリーパーが非常に速くなります。

これが私のコードです:

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、ボタンのパラメーターを変更しています。だから、それはまさにアニメーションが停止したことになります。しかし、実際にそれが起こる点滅の瞬間を見ることができます。

それはなぜですか、どうすれば修正できますか?

ありがとう!

4

2 に答える 2

0

これを追加してみてください

TAnimation.setFillBefore(true);

アニメーションオブジェクトに。

于 2012-08-23T07:22:48.493 に答える
0

あなたは与えてみることができます

TAnimation.setFillAfter(true); 

私はそれがあなたの問題を解決すると思います

于 2013-06-25T19:00:03.737 に答える