如何平滑地动画隐藏工具栏及其下方的内容。

How to smoothly animate the hiding of the toolbar plus something below it.

我正在使用 appcompat 工具栏作为我的操作栏,我在它的正下方有一个布局,还有一些视图,它与工具栏的高度大致相同。

当 activity 的主视图(位于它们下方)发生滚动时,我将它们隐藏在一起并且它运行良好但隐藏太突然,我想做到这一点顺利发生。我看过很多关于如何对工具栏执行此操作的帖子,但我还没有找到任何用于隐藏工具栏及其下方的内容的帖子,那么如何顺利地隐藏和显示两者?

基本上我所拥有的是:

<android.support.v7.widget.Toolbar .../>
<RelativeLayout .../>

谢谢。

我认为你必须在工具栏上使用 alpha 动画和 translationY 动画 即

                view.animate()
                        .translationY(0)
                        .alpha(1).setDuration(HEADER_HIDE_ANIM_DURATION)
                        .setInterpolator(new DecelerateInterpolator());

更多信息请参考google Ioschedule 应用程序源代码。

我在 github HideOnScroll you can read about this repository by the author who has given nice explanation on how to hide toolbar here is the other link Blog Link

上找到了这个 link