android棒棒糖工具栏:如何在滚动时隐藏/显示工具栏? [英] android lollipop toolbar: how to hide/show the toolbar while scrolling?

查看:32
本文介绍了android棒棒糖工具栏:如何在滚动时隐藏/显示工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 appcompat/support-v7 中引入的新工具栏小部件.我想根据用户是否向上/向下滚动页面来隐藏/显示工具栏,就像在新的 Google Playstore 应用程序或 NewsStand 应用程序中一样.工具栏小部件中是否为此内置了一些东西,或者我应该将它与 FrameLayout 和 ObservableScrollView 结合使用吗?

I'm using the new toolbar widget introduced in the appcompat / support-v7. I would like to hide/show the toolbar depending on if the user is scrolling up/down the page, just like in the new Google's playstore app or NewsStand app. Is there something built into the toolbar widget for this or should I be using it in conjunction with FrameLayout and ObservableScrollView?

推荐答案

据我所知,没有任何内置功能可以为您做到这一点.但是,您可以查看 Google IO 源代码,尤其是 BaseActivity.搜索自动隐藏"或查看 onMainContentScrolled

As far as I know there is nothing build in that does this for you. However you could have a look at the Google IO sourcecode, especially the BaseActivity. Search for "auto hide" or look at onMainContentScrolled

为了隐藏 Toolbar 你可以这样做:

In order to hide the Toolbar your can just do something like this:

toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();

如果您想再次显示它,请调用:

If you want to show it again you call:

toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();

这篇关于android棒棒糖工具栏:如何在滚动时隐藏/显示工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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