Q:

TabLayout scroll without a recyclerView

I am using the new material design libraries:
 compile 'com.android.support:design:22.2.0'
 compile 'com.android.support:appcompat-v7:22.2.0'
 compile 'com.android.support:recyclerview-v7:22.2.0'

And I have the typical simple layout (3 tabs) as in the cheesquareapp

Here each tab fragment is a simple RecyclerView
layout - fragment_cheese_list.xml
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

And it works great.
But what I would like is to change the layout fragment_cheese_list.xml to have other items.
Such as this for example.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:visibility="gone"/>

    <LinearLayout
        android:id="@+id/empty_list_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No results, tap button to search again"/>

        <Button
            android:id="@+id/btn_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Search"/>

    </LinearLayout>

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

    android:visibility="gone"/>

</LinearLayout>

As you can see here, I would like to only show the RecyclerView when there are items, and if there are no items, I hide it to show the button and text.
I do this by switching visibilities (View.GONE - View.VISIBLE).
I have all of this done already, the problem is that when RecyclerView is NOT visible, I cannot "scroll" the layout to hide/show the toolbar like the last image in this picture

So this brings a lot of problems, like if I switch from one tab to this one, while having the toolbar completely hidden, then I cannot show the toolbar again, unless I switch tabs and scroll to show it.
Thanks
EDIT: Maybe there is a way to programatically code that when the viewpager changes, hide/show with animation the toolbar. Although this is not the best solution it could be a workaround, if anyone knows anything about this please post how to code it (tried some code which did not work)

A:

You need wrap your button & label with NestedScrollView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
>

<ProgressBar
    android:id="@+id/progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="gone"
    />

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    >

    <LinearLayout
        android:id="@+id/empty_list_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No results, tap button to search again"
            />

        <Button
            android:id="@+id/btn_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Search"
            />

    </LinearLayout>

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:visibility="gone"
    />

</LinearLayout>

