简体   繁体   中英

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); .

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

<?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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM