【问题标题】:How to animate an ImageButton into invisibility如何将 ImageButton 设置为不可见状态
【发布时间】:2016-05-18 23:20:49
【问题描述】:

这是对Animate ImageView from alpha 0 to 1 的跟进。

我有一个 ImageButton,我想在用户执行 X 时将其动画化到视图中,然后在用户执行 Y 时将其动画化到视图之外。动画 进入 视图工作正常。但是在视野之外制作动画是行不通的。事实上它正在工作,因为动画发生了。但是在按钮淡出视图后,它会以可见的形式弹回。所以我使用这个代码

AlphaAnimation animation1 = new AlphaAnimation(0.9f, 0.0f);
        animation1.setDuration(5000);
        animation1.setStartOffset(1000);
        animation1.setFillAfter(true);
        animation1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                GVLog.d(TAG,"MAKE INVISIBLE onAnimationStart: %s",tokenBtn.getVisibility());
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                GVLog.d(TAG,"MAKE INVISIBLE onAnimationRepeat: %s",tokenBtn.getVisibility());
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                tokenBtn.setVisibility(View.INVISIBLE);
                GVLog.d(TAG,"MAKE INVISIBLE onAnimationEnd: %s",tokenBtn.getVisibility());

            }
        });
        tokenBtn.startAnimation(animation1);

但是使 ImageButton 不可见的调用没有生效。那么如何让它生效,让 ImageButton 保持不可见呢?

【问题讨论】:

标签: android android-layout animation alpha-transparency


【解决方案1】:

试试这样。这些代码始终适用于我的应用。

AlphaAnimation animation1 = new AlphaAnimation(1, 0);
animation1.setDuration(1000);

tokenBtn.startAnimation(animation1);
tokenBtn.setVisibility(View.INVISIBLE);

【讨论】:

  • 您的建议与我将其放入 onAnimationStart 时的行为相同。这种方法的问题在于,如果图像是 GIF,它会在消失时停止动画。
猜你喜欢
  • 2016-12-27
  • 2015-04-08
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 2015-12-17
  • 2012-01-30
  • 1970-01-01
  • 2011-08-05
相关资源
最近更新 更多