2

Below is the code snippet, can someone please help me? My collapsing toolbar is not collapsing at all. Intended behavior is : as I scroll up, the toolbar should collapse from 168dp to 56dp. But it is not collapsing at all. Thanks in advance.

<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:background="@color/one_primaryColor"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="168dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            app:layout_collapseMode="pin">

            <ImageView
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:contentDescription="@string/app_name"

            app:layout_collapseMode="parallax"
            android:src="@drawable/logo" />

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView...
NightFury
  • 13,436
  • 6
  • 71
  • 120
inkedTechie
  • 684
  • 5
  • 13

2 Answers2

5

EDIT:

I played with your layout. You have to use NestedScrollView in order to make your layout follow scroll behavior of CollapsingToolbarLayout. Following is the working xml code:

<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:background="@color/one_primaryColor">


        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="168dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="parallax">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/app_name"
                    android:src="@drawable/logo" />

            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

        </RelativeLayout>

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

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

But there is an issue with this approach. If you put RecyclerView inside NestedScrollView when root parent is CoordinatorLayout. Recycler's content won't be displayed, although all the adapter methods are called. Reason behind is the nesting of scroll layout inside scroll. Most probably Recycler's layout is not rendered due to this reason. For that, work around has been followed from this post.

In your code, use WrappingLinearLayoutManager class as layout manager for recycler view.

    //Your custom adapter
    Adapter adapter = new Adapter(cursor);
    adapter.setHasStableIds(true);
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setNestedScrollingEnabled(false);

    int columnCount = getResources().getInteger(R.integer.list_column_count);
    WrappingLinearLayoutManager wrappingLinearLayoutManager =
            new WrappingLinearLayoutManager(columnCount, LinearLayout.VERTICAL);
    mRecyclerView.setLayoutManager(wrappingLinearLayoutManager);

This should solve your problem. If it still doesn't work, I can upload it somewhere for you.

Community
  • 1
  • 1
NightFury
  • 13,436
  • 6
  • 71
  • 120
  • sorry dude, i copy-pasted your code but it is not working, if it helps you can check it on https://github.com/saikiapriyam/MakeYourAppMaterial – inkedTechie Jun 13 '16 at 05:15
  • Where I do need to see in that project? – NightFury Jun 13 '16 at 05:50
  • oops, sorry please look @Lara https://github.com/saikiapriyam/MakeYourAppMaterial/blob/master/src/main/res/layout/material_activity_article_list.xml – inkedTechie Jun 13 '16 at 06:05
0

Just in case anybody else bumped into the same problem, I'm gonna post the solution to my issue. The problem was with the support-library version, I was using 22.0.0. In this version, the SwipeRefreshLayout does not support CollapsibleToolbar behavior, it was a bug that got resolved in the 23.0 version. So, I updated my support - libaries to 23.0.0 and it got resolved! yeay!

inkedTechie
  • 684
  • 5
  • 13