TabLayout hide/show 动画

TabLayout hide/show animation

我有 ToolbarTabLayout,我想在某些时候 hide/show,我想为选项卡的 hide/show 过程设置动画(工具栏仍然可见)...在 TabLayout 上放置缩放动画会隐藏它,但工具栏的高度保持不变,就好像选项卡在那里一样...有什么建议吗?

 public void showTabs(boolean show) {
        if (show) {
          //tabLayout.setVisibility(View.VISIBLE);
            tabLayout.animate().scaleY(1).setInterpolator(new DecelerateInterpolator()).start();

        } else {
            tabLayout.animate().scaleY(0).setInterpolator(new AccelerateInterpolator()).start();
            //tabLayout.setVisibility(View.GONE);
        }
    }

您需要将 android:animateLayoutChanges="true" 设置为您的 AppBarLayout,而在您的 JAVA 中只需使用 tablLayout.setVisibility(View.VISIBLE)tablLayout.setVisibility(View.GONE) 以获得可见性并享受结果!