动画后按钮消失 [英] Button Disappears After Animation

查看:95
本文介绍了动画后按钮消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在触摸时进行动画处理的按钮。动画正在工作,但是在动画完成后,我正在调用setAnimation(null)来重置按钮,但是按钮没有回到其默认位置。

i have a button that i animating when touched. the animation is working but after the animation is compelete, i am calling setAnimation(null) to reset the button, but the button is not getting back to its default position.

这是代码:

ok_btn_id.setOnTouchListener(new OnSwipeTouchListener(BarCodeReaderActivity.this) {
            public void onSwipeTop() {
            }
            public void onSwipeRight() {

                slidefromLeftToRight(ok_btn_id);
            }
            public void onSwipeLeft() {
                slidefromRightToLeft(ok_btn_id);
            }
            public void onSwipeBottom() {
            }
        });

public void slidefromRightToLeft(final View view)
    {
        TranslateAnimation animate;

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        if (view.getHeight() == 0) {
            animate = new TranslateAnimation(metrics.widthPixels/2,
                    0, 0, 0);
        } else {
            animate = new TranslateAnimation(0,-viewGroup.getWidth(), 0, 0); // View for animation
        }

        animate.setDuration(500);
        animate.setFillAfter(false);

        view.startAnimation(animate);
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
               view.setAnimation(null);
                view.setVisibility(View.VISIBLE); 
            }
        }, 500);
    }


推荐答案

请尝试以下操作:

animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            aView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            button.clearAnimation();

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

希望这对您有所帮助。

这篇关于动画后按钮消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆