简体   繁体   English

在NestedScrollView中使用recyclerView时如何隐藏滚动条上的工具栏

[英]how to hide toolbar on scroll when using recyclerView inside NestedScrollView

I am using NestedScrollView which is used to hide toolbar on scroll but when i put recyclerView inside it ,toolbar is not hiding on scroll and i used evry possible answer in stackoverflow but nothings worsks and specially i used recyclerView.setNestedScrollingEnabled(false); 我正在使用NestedScrollView,用于在滚动条上隐藏工具栏,但是当我将recyclerView放入滚动条中时,工具栏不会在滚动条上隐藏,并且我在stackoverflow中使用了可能的答案,但是没有问题,特别是我使用了recyclerView.setNestedScrollingEnabled(false); .

Here is my code: 这是我的代码:

<android.support.v4.widget.NestedScrollView 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"

    app:layout_behavior="@string/appbar_scrolling_view_behavior">

<RelativeLayout

    android:layout_width="match_parent"
    android:background="#fff"
    android:layout_height="wrap_content"
    >



    <android.support.v7.widget.RecyclerView



        android:id="@+id/recyclerView"
        android:background="#fafafa"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

    <ProgressBar
        android:id="@+id/progressBar1"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>

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

--- EDIT----------- ---编辑-----------

<?xml version="1.0" encoding="utf-8"?>


<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/DrawerLayout"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">
    <include
        android:id="@+id/includeAppBar"
        layout="@layout/app_bar_navigation_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"

        android:background="#ffffff"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>

----EDIT 2---- ----编辑2 ----

<?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.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:theme="@style/ThemeOverlay.AppCompat.Dark">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            app:theme="@style/ToolBarStyle"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_height="?attr/actionBarSize"
            />


        <!-- our tablayout to display tabs  -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#fff"
            app:tabTextColor="#a6a2a2"
            app:tabSelectedTextColor="#0099ff"
            app:tabIndicatorColor="#0099ff"


            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
    </android.support.design.widget.AppBarLayout>
    <!-- View pager to swipe views -->
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"/>






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

You can try this, add this attibute to your AppBarLayout : 您可以尝试将其添加到您的AppBarLayout中:

app:layout_scrollFlags="scroll|exitUntilCollapsed"

EDIT: 编辑:

Change your code as below as well : 如下更改代码:

<?xml version="1.0" encoding="utf-8"?>


<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/DrawerLayout"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">
    <include
        android:id="@+id/includeAppBar"
        layout="@layout/app_bar_navigation_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" // new attibute
        android:background="#ffffff"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>

Hope this helps. 希望这可以帮助。

Sorry for my english. 对不起我的英语不好。

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

相关问题 在片段内而不是活动内使用recyclerview时,在滚动条上隐藏工具栏 - Hide toolbar on scroll when the using a recyclerview inside a Fragment instead of an Activity 如果我向下滚动片段中的recyclerView,如何自动隐藏工具栏? - How to hide toolbar automatically if I scroll down the recyclerView inside a fragment? NestedScrollView 内的 Recyclerview - 滚动到底部 - Recyclerview inside NestedScrollView - Scroll to bottom RecyclerView 滚动在 NestedScrollView 内不起作用 - RecyclerView Scroll Not Working Inside NestedScrollView NestedScrollView内的RecyclerView比RecyclerView滚动得更快 - RecyclerView inside NestedScrollView scroll faster than RecyclerView LinearLayout 和 NestedScrollView 中的 RecyclerView - 如何滚动到某个位置的项目顶部? - RecyclerView inside LinearLayout and NestedScrollView - How to scroll to top of item on a certain position? 无法在BottomSheetBehavior内的NestedScrollView内滚动RecyclerView - Unable to scroll RecyclerView inside NestedScrollView inside BottomSheetBehavior 使用滚动RecyclerView时如何在ViewPager中隐藏工具栏? - How to hide the toolbar in a ViewPager when using Scrolling RecyclerView? 检查nestedscrollview中的recyclelerview滚动状态 - Check recyclerview scroll state inside nestedscrollview NestedScrollView中的RecyclerView-滚动不起作用 - RecyclerView inside NestedScrollView - scroll wont work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM