簡體   English   中英

即使在提供“app:layout_scrollFlags”標志后,工具欄也不會滾動

[英]Toolbar is not scrolling off even after providing “app:layout_scrollFlags” flag

我正在嘗試工具欄和TabLayout,當你滾動循環視圖時,它應該像whatsapp應用程序一樣隱藏工具欄。 我指的是谷歌博客Michal Z的博客 我在主要活動中查看了尋呼機,我正在使用recycleview顯示其中的數據列表。

坦率地說,我被新的谷歌設計庫所震撼,因為只需一行XML代碼就可以改變完整的UI和UI行為。 所以想要這個功能,我們需要在工具欄中添加app:layout_scrollFlags="scroll|enterAlways"行,它才能正常工作。 但對我來說它不起作用。 我已在API 19和21設備上測試過它。

通過在堆棧溢出和各種博客 博客上的問題 問題 ,我找到2種方法來實現此功能1.通過提供滾動偵聽器到recycleview和2.通過將可滾動內容放在NestedScrollView 但它沒有按預期工作。

我認為它應該沒有編寫任何代碼。

主Activity.xml

<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">

    <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:background="@color/colorPrimary"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/Base.ThemeOverlay.AppCompat.Dark"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:background="@color/colorPrimaryDark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

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

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

ViewPagerFragment.xml

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/windowBackground">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/order_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft= "true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/txtStatus" />

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

你的布局似乎是正確的。
檢查您的build.gradle版本的recyclerView是否正好是22.2.0buildToolsVersion22.0.1 您需要這樣做,因為所有這些新功能都出現在此處提到的22.2.0版本的支持庫中。

暫無
暫無

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

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