Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Gridview未显示/隐藏工具栏_Android_Gridview_Android Design Library - Fatal编程技术网

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