简体   繁体   English

如果我向下滚动片段中的recyclerView,如何自动隐藏工具栏?

[英]How to hide toolbar automatically if I scroll down the recyclerView inside a fragment?

Just Like my title says, I was trying to hide my toolbar dynamically when I scroll down the RecycledView inside of a fragment by using the coordinator layout. 就像我的标题所说的那样,当我使用协调器布局向下滚动片段内的RecycledView时,我试图动态隐藏工具栏。 But it is not working. 但这是行不通的。 I think it is because something wrong with my XML file. 我认为这是因为我的XML文件有问题。 I will be really grateful if someone helps me. 如果有人帮助我,我将非常感激。

Here is my fragment XML file, this fragment is contained inside a tab layout: 这是我的片段XML文件,该片段包含在选项卡布局中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jinyu.jiaodian.MainActivity"
>

<android.support.v7.widget.RecyclerView
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:id="@+id/my_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    />
<android.support.design.widget.FloatingActionButton
    android:id="@+id/upload_a_word"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_input_add"
    android:layout_alignParentRight="true" />

Here is my app_bar layout: 这是我的app_bar布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout       xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.jinyu.jiaodian.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<include
    layout="@layout/tab_layout"/>

Put app:layout_behavior="@string/appbar_scrolling_view_behavior" on your include , not on the AppBarLayout . app:layout_behavior="@string/appbar_scrolling_view_behavior"放在您的include ,而不放在AppBarLayout That behavior is what propagates nested scrolling events to your AppBarLayout . 该行为就是将嵌套滚动事件传播到您的AppBarLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我向上滚动 RecyclerView 时,工具栏和 TabLayout 不会隐藏 - Toolbar and TabLayout don't hide when I scroll the RecyclerView up 如何在片段中隐藏工具栏? - How to hide toolbar in a fragment? 如何隐藏片段中工具栏中的OptionMenu? - How do I hide the OptionMenu in a toolbar from a fragment? 检测片段中 Recyclerview 上的上下滑动我该怎么做? - Detecting up and down swipes on a Recyclerview in a fragment how can I do that? 当我向下滚动时,滚动以在recyclerview中添加项目总是自动显示在顶部 - on scrolled to add items in recyclerview always comes to top automatically when i scroll down 如何在片段中隐藏MainActivity工具栏中的项目 - How to hide item from the MainActivity toolbar in a fragment 如何使工具栏隐藏在滚动Android Studio上 - How to make toolbar hide on scroll android studio 如何使recyclerview无限滚动(向下/向上)? - how to make a recyclerview infinite scroll (down / up)? 如何将自定义工具栏放在片段中? - How to put custom toolbar inside fragment? 如何使用 RecyclerView 逐步加载带有 RecyclerView 的屏幕滚动屏幕? - How do I scroll the screen with the RecyclerView inside with RecyclerView load items step by step?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM