android - 在动画后设置 LinearLayout 的可见性

标签 android android-layout android-linearlayout

我在我的 xml 文件中创建了一个 LinearLayout,它的可见性设置为 Gone。然后我使用动画显示它,这很好。

我使用 AlphaAnimation 淡出我的 LinearLayout 并且效果很好。

我的问题

问题是,当我使用 AnimationListener 收听动画并调用 onAnimationEnd 方法时,它没有设置我的 LinearLayout 的可见性GONE,因为我仍然可以单击其中的 ImageButtons,这就是我知道它们仍然存在的原因。

这是我的 xml 和我的 LinearLayout。

<LinearLayout
        android:id="@+id/photoOptionBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:alpha="1"
        android:background="@color/gpsBackground"
        android:orientation="horizontal"
        android:visibility="gone">

        <ImageButton
            android:id="@+id/displayShareBtn"
            style="@android:style/Widget.Holo.Button.Borderless.Small"
            android:background="@android:color/transparent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:padding="20dp"
            android:src="@drawable/share"
            android:contentDescription="Share the picture"/>

        <ImageButton
            android:id="@+id/displayDiscardBtn"
            style="@android:style/Widget.Holo.Button.Borderless.Small"
            android:background="@android:color/transparent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:padding="20dp"
            android:src="@drawable/contentdiscard"
            android:contentDescription="Discard Picture"/>

    </LinearLayout>

这是我的淡出方法和监听器。

AlphaAnimation alpha = new AlphaAnimation(1.0F, 0.0F);
    alpha.setDuration(PhotoDisplayFragment.FADE_DURATION); // Make animation instant
    alpha.setFillAfter(true); // Tell it to persist after the animation ends
    // And then on your layout
    final LinearLayout temp = this._photoOptionsBar;
    alpha.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            // TODO Auto-generated method stub
            temp.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

    });
    this._photoOptionsBar.startAnimation(alpha);

我的问题

如何在动画结束后将 LinearLayout 的可见性设置为 GONE

提前致谢

最佳答案

此问题与 setFillAfter 有关,它让动画在完成后继续存在。删除,一切都会按预期工作。如果您需要动画淡入淡出,请检查 _photoOptionsBar 可见性,如果它消失了,请应用反向动画:

new AlphaAnimation(0.0F, 1.0F);

关于android - 在动画后设置 LinearLayout 的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13029540/

相关文章:

android - 如何更改 CalendarView 中的月份文本颜色

android - 如何在 Horizo​​ntalScrollView 内的 LinearLayout 中正确显示按钮?

android - 使线性布局像 ListView 中的列表项一样可选择(Android)

android visibility - ImageView 的预留空间

android - java.lang.NullPointerException : at android. widget.Editor.updateFloatingToolbarVisibility

android - 帮助纠正 Android OpenGL 2.0 w/QCAR 中的线缩放

android - 菜单项(状态栏)和 RecyclerView 项之间的交互?

Android Studio 无法启动守护进程

android - 缩小抽屉导航中部分元素的textSize

android - 以编程方式在另一个布局中添加布局