工具栏无法隐藏在列表滚动

时间:2015-12-21 22:43:04

标签: android listview android-tabs

因此,我使用CoordinatorLayout进行此主要活动布局,以在其下方显示工具栏和标签:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        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/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="0dp"
            local:layout_scrollFlags="scroll|enterAlways"
            local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            local:tabMode="fixed"
            local:tabGravity="fill"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:foreground="@drawable/header_shadow"
        local:layout_behavior="@string/appbar_scrolling_view_behavior"  />

</android.support.design.widget.CoordinatorLayout>

然后我有2个片段布局,每个片段布局都是我所拥有的2个标签中的每一个。一个片段在其内容上显示ListView

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@drawable/header_shadow"
    tools:context=".StationsFragment">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <ListView
            android:id="@+id/stations_listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

</FrameLayout>

当我滚动上面的列表视图时,我希望我的工具栏可以隐藏,而且我的代码应该没问题,至少从我在answer中读到的内容开始,但它不起作用。目前我已尝试从片段活动中删除FrameLayout,但这并未解决问题。我已经考虑过对listview中的滚动事件进行硬编码,但如果可能的话,我真的希望这个没有代码可以使用..

提前致谢。

2 个答案:

答案 0 :(得分:2)

这是因为您将CoordinatorLayoutListView一起使用。您可以将实施更改为RecyclerView以实现正确的滚动。

检查我的回答here。这可能会对你有帮助。

答案 1 :(得分:0)

尝试从

进行更改
local:layout_scrollFlags="scroll|enterAlways"

local:layout_scrollFlags="scroll|exitUntilCollapsed"