Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar is not scrolling off even after providing "app:layout_scrollFlags" flag

I am trying implement Toolbar and TabLayout in which when you scroll the recycleview it should hide toolbar just like whatsapp application. I was referring google Blog and Michal Z's Blog. I have view pager in main activity and i am showing list of data inside it using recycleview.

Frankly speaking i was blown away by new google design library because with just one line of XML code it can change the complete UI and UI behavior. So idealy for this functionality we need to add app:layout_scrollFlags="scroll|enterAlways" line in toolbar and it just works. But for me its not working. I have tested it on API 19 and 21 devices.

By going through question question on stack overflow and various Blog Blog i found 2 way to achieve this functionality 1. by providing scroll listener to recycleview and 2. by putting scrollable content inside NestedScrollView. But it didnt work as expected.

I think it should work without writing any code.

Main 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>
like image 910
Vinit Thaker Avatar asked Jul 17 '15 14:07

Vinit Thaker


1 Answers

Your layout seems to be correct.
Check that in your build.gradle version of recyclerView is exactly 22.2.0 and buildToolsVersion is 22.0.1. You need to do it because all those new features appeared in the 22.2.0 version of support library as mentioned here.

like image 119
Mikhail Avatar answered Nov 13 '22 05:11

Mikhail