setVisibility(View.GONE)不会消失视图 [英] setVisibility(View.GONE) doesn't disappear a view

查看:697
本文介绍了setVisibility(View.GONE)不会消失视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的活动,我有一个启动按钮,并单击时应该淡出,最后由 setVisibility(View.GONE)消失

In my activity, I have a start button, and when that's clicked it should fade out and finally disappear by setVisibility(View.GONE)

问题是可见性设置为GONE不消失的观点,它仍然是可见的。我故意做出的观看动画淡出到0.1(而不是0),我可以看到它在我打过电话后连背景 setVisibility(View.GONE)就可以了。

The problem is setting visibility to GONE doesn't disappear the view, it's still visible. I've purposefully made the view animation fade out to 0.1 (instead of 0) and I can see it in the background even after I've called setVisibility(View.GONE) on it.

淡出动画 anim_fade_out.xml 是:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true" android:fillEnabled="true">

        <alpha
            android:fromAlpha="1.0"
            android:toAlpha="0.1"
            android:duration="200" />
</set>

该方法 showTimer()

private void showTimer() {
    final LinearLayout startButtonArea = (LinearLayout)findViewById(R.id.startButtonArea);      

    Animation animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim_fade_out);

    startButtonArea.startAnimation(animFadeOut);

    animFadeOut.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            startButtonArea.setVisibility(View.GONE);
            Log.d("Animation ended","startButtonArea SHOULD BE GONE BUT IT ISN'T");
        }
        @Override
        public void onAnimationRepeat(Animation animation) {}
        @Override
        public void onAnimationStart(Animation animation) {}    
    });

}

要重申,我知道,在动画的最后alpha是0.1(这将是0通常情况下),但我想确认的看法是真的 GONE ,它不是。

To reiterate, I know that the end alpha of the animation is 0.1 (it would be 0 usually) but I want to confirm that the view is really GONE and it isn't.

推荐答案

由于您的 fillAfter 是真实的,动画的 onAnimationEnd后设置属性被调用。您可以更改 fillAfter 为假,像这样做:

Because your fillAfter is true, the animation sets the properties after your onAnimationEnd is called. You can either change fillAfter to false, or do it like this:

@Override
public void onAnimationEnd(Animation animation) {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            startButtonArea.setVisibility(View.GONE);
            Log.d("Animation ended","startButtonArea SHOULD BE GONE BUT IT ISN'T");
        }
    }, 0);
}

这篇关于setVisibility(View.GONE)不会消失视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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