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

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

问题描述

我正在使用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源代码,尤其是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 Lollipop工具栏:如何在滚动时隐藏/显示工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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