Android Show隐藏LinearLayout

吉姆·佛考伦(Jim Vercoelen)

正在尝试在LinearLayout上管理显示/隐藏动画的此应用程序上工作。

我遇到的问题是,在切换可见性时,似乎第二次隐藏了任何孩子。

为了使我的故事更加清晰,此处是屏幕截图:

  • 开始时-隐藏
  • 第一次单击-显示带有子项的线性布局(textview)
  • 第2次点击-再次隐藏线性布局
  • 第3次点击-显示线性布局,但没有子级(文本视图)

在此处输入图片说明

布局文件:

        <TextView
            android:id="@+id/tv_lecture"
            style="@style/Text.Primary.Light"
            android:singleLine="true" />

        <LinearLayout
            android:visibility="gone"
            android:id="@+id/grades_container"
            style="@style/Container.Vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="10"/>
        </LinearLayout>

代码:

private void animate(final LinearLayout gradesContainer) {
    if (gradesContainer.getVisibility() == View.GONE) {
        gradesContainer.animate()
                .translationY(gradesContainer.getHeight())
                .alpha(1.0f)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        super.onAnimationStart(animation);
                        gradesContainer.setVisibility(View.VISIBLE);
                        gradesContainer.setAlpha(0.0f);
                    }
                });
    }
    else {
        gradesContainer.animate()
                .translationY(0)
                .alpha(0.0f)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        gradesContainer.setVisibility(View.GONE);
                    }
                });
    }
}

在讲座TextView上,单击将触发该方法:animate()

那么,这里出了什么问题?不能弄清楚那就是为什么我要问你们。谢谢!

AL。

如果您只针对简单的动画。您可以继续并animateLayoutChanges在xml中使用

干杯! :)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章