【问题标题】:Toolbar is not scrolling off even after providing "app:layout_scrollFlags" flag即使提供“app:layout_scrollFlags”标志,工具栏也不会滚动
【发布时间】:2015-10-07 08:12:23
【问题描述】:

我正在尝试实现 Toolbar 和 TabLayout,当您滚动回收视图时,它应该像 whatsapp 应用程序一样隐藏工具栏。我指的是谷歌BlogMichal Z's Blog。我在主要活动中有查看寻呼机,我正在使用 recycleview 显示其中的数据列表。

坦率地说,我被新的谷歌设计库所震撼,因为只需一行 XML 代码就可以改变完整的 UI 和 UI 行为。所以理想情况下,我们需要在工具栏中添加app:layout_scrollFlags="scroll|enterAlways" 行,它就可以工作了。但对我来说它不起作用。我已经在 API 19 和 21 设备上对其进行了测试。

通过查看堆栈溢出时的question question 和各种Blog Blog,我找到了实现此功能的两种方法: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 文件。
  • 我遇到了同样的问题,appbarlayout 在 api 9 平板电脑上没有滚动

标签: android android-toolbar android-design-library android-coordinatorlayout android-appbarlayout


【解决方案1】:

您的布局似乎是正确的。
检查您的build.gradle 版本中的recyclerView 是否正好是22.2.0buildToolsVersion22.0.1。您需要这样做,因为所有这些新功能都出现在 22.2.0 版本的支持库中,如 here 所述。

【讨论】:

  • buildToolsVersion 是 22.0.1,但我使用“v7:22.0.+”版本进行回收查看。现在我将其更改为 22.2.0,它按预期工作。谢谢阿卡迪亚
  • 我正在使用 v7:23.3.0 但它对我来说有一段时间没用了
猜你喜欢
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
  • 2013-06-10
  • 2015-10-21
  • 1970-01-01
  • 2021-01-01
相关资源
最近更新 更多