Android Gridview未显示/隐藏工具栏
我使用的是设计支持库,我使用的是Android Gridview未显示/隐藏工具栏,android,gridview,android-design-library,Android,Gridview,Android Design Library,我使用的是设计支持库,我使用的是网格视图,但当我向上或向下滚动到网格时,工具栏不会隐藏或显示。我在一个RecyclerView上使用了相同的代码,它工作得很好 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
网格视图
,但当我向上或向下滚动到网格时,工具栏
不会隐藏或显示。我在一个RecyclerView
上使用了相同的代码,它工作得很好
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<GridView
android:id="@+id/gridView1"
android:numColumns="2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
这是我活动中的*.xml文件。我只是
设置支持操作栏(工具栏)
并初始化GridView适配器。假设您使用协调布局作为父布局,您需要使用RecyclerView
或NestedScrollView
使其正常工作当前ListView
和GridView
与CoordinatorLayout
的预期行为仅与API>21相关
要获得此行为,必须设置:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gridView.setNestedScrollingEnabled(true);
}
您可以找到更多信息。尝试将GridView包含在NestedScrollView中。根据用户迄今为止的报告,只有RecyclerView和NestedScrollView与CoordinatorLayout合作。我能想到的唯一其他解决方案是(如果可能的话)在实现GridLayoutManager的RecyclerView中转换您的GridView