簡體   English   中英

工具欄不會隱藏在列表滾動中

[英]Toolbar doesn't hide on list scroll

因此,我有一個使用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>

當我滾動上方的列表視圖時,我希望隱藏我的工具欄,並且使用我擁有的代碼應該可以,至少從我在此答案中讀到的內容可以,但它無法正常工作。 目前,我試圖從fragment活動中刪除FrameLayout ,但這並不能解決問題。 我已經考慮過對列表視圖中的滾動事件進行硬編碼,但是如果可能的話,我真的希望它可以在沒有任何代碼的情況下工作。

提前致謝。

這是因為您將CoordinatorLayoutListView一起使用。 您可以將實現更改為RecyclerView以實現正確的滾動。

在這里檢查我的答案。 這可能對您有幫助。

嘗試從

local:layout_scrollFlags="scroll|enterAlways"

local:layout_scrollFlags="scroll|exitUntilCollapsed"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM