如何隐藏动作条,而在Android的滚动的ListView? [英] How to hide ActionBar while scrolling ListView in android?
问题描述
我需要创建一个列表视图和动作条它向下滚动时和滚动的时候了,必须重新出现将隐藏的接口。
I need to create an interface with a listview and an actionbar which will hide when scrolling down and when scrolling up it must reappear.
下面的指南并没有帮助我:
The following guides didn't help me:
<一个href="https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling%28part3%29/" rel="nofollow">https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling%28part3%29/ https://github.com/ksoichiro/Android-ObservableScrollView
我需要的是这样的:
推荐答案
如果你想获得一个列表,此行为,您应该:
If you would like to obtain a list with this behaviour, you should:
- 添加与
设计支持库编译com.android.support:design:22.2.0
- 使用一个
CoordinatorLayout
有一个工具栏,你必须定义应用程序:layout_scrollFlags =滚动| enterAlways
- 使用一个的
RecyclerView
代替的ListView
。如上所述<一个href="http://stackoverflow.com/questions/30696611/design-lib-coordinatorlayout-collapsingtoolbarlayout-with-gridview-listview/30885092#30885092">here的ListView
和的GridView
有预期的行为CoordinatorLayout
只有API> 21。在这种情况下,你必须使用setNestedScrollingEnabled(真);
- add the design support library with
compile 'com.android.support:design:22.2.0'
- Use a
CoordinatorLayout
with a Toolbar where you have to defineapp:layout_scrollFlags="scroll|enterAlways"
- Use a
RecyclerView
instead of aListView
. As described hereListView
and theGridView
have the expected behavior with theCoordinatorLayout
only with API>21. In this case you have to usesetNestedScrollingEnabled(true);
href="http://android-developers.blogspot.de/2015/05/android-design-support-library.html" rel="nofollow">官方博客帖子的
The official blog post shows this case:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<! -- Your Scrollable View -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
...
app:layout_scrollFlags="scroll|enterAlways">
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
这篇关于如何隐藏动作条,而在Android的滚动的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!