2

I have used the coordinator layout to acheive the bar collapsing the action bar.
Now my problem is that I scroll just small enough to hide action bar partially the below stays there.
What I want is that even if I leave it hidden partially; it (the bar below with few button) should merge with action bar.(Similar to Whatsapp)
My code is:

<android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <include
                android:id="@+id/app_bar_layout"
                layout="@layout/pmp_toolbar_2" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/pmp_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

The action bar when scrolled a bit looks like:
enter image description here

And my build.gradle file is

compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'

UPDATE: See abhishek's comment; this issue is resolved in library update

AnswerDroid
  • 1,873
  • 2
  • 33
  • 52
  • What do you mean by merging? If you want it to dissapear, use fullscreen. Otherwise, let it there and don't make action bar scrollable. – mrek Sep 15 '15 at 09:42
  • 1
    @mrek actually what the bar you are seeing below (with icons) collapses with action bar – AnswerDroid Sep 15 '15 at 09:50
  • I am sorry but I don't understand what do you mean exactly. – mrek Sep 15 '15 at 15:08
  • 1
    @mrek the problem is that I want the action bar behavior exactly as that of whatsapp. You try to leave the action bar at this stage in whatsapp; it wont stay. It will either move up or move down – AnswerDroid Sep 16 '15 at 04:14
  • do you think [this](https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling(part3)/) behaviour? I think it is because of `include` branch which overrides the usual behavior. Check that tutorial above - it could be helpful. – mrek Sep 16 '15 at 07:56
  • @mrek the problem is the same as that of the first comment in the link you provided – AnswerDroid Sep 16 '15 at 08:13
  • @AnswerDroid I may have a workaround for you. Please see my answer. – Vicky Chijwani Oct 04 '15 at 12:19
  • This feature has been added in `23.1.0` version of support library. http://stackoverflow.com/questions/31839173/how-to-make-the-toolbar-snap-into-view-or-out-of-view-when-using-google-design-l/33163714#33163714 – Abhishek V Oct 16 '15 at 06:19

3 Answers3

4

This is a known issue with Toolbar in the Android Design Support Library. It is marked as "FutureRelease" in the Android issue tracker since 9th September, which means the fix should be out soon. Note, the fix has not been released yet.

EDIT: if you really want to fix this yourself now, there is a workaround posted in this other question: https://stackoverflow.com/a/32089807/504611 (found this link through the bug report itself).

LATEST EDIT (RESOLVED): This is fixed in support library v23.1.0. See How to make the Toolbar snap into view or out of view when using Google Design Library?

Community
  • 1
  • 1
Vicky Chijwani
  • 10,191
  • 6
  • 56
  • 79
2

I'm using following layout to achieve scroll effect like whatsapp

<?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"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            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.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_done" />

</android.support.design.widget.CoordinatorLayout>
ch3tanz
  • 3,070
  • 3
  • 16
  • 24
  • I have done similar thing , but I will check and see if it works – AnswerDroid Sep 30 '15 at 04:42
  • I think you misunderstood my question I guess.. I dont have challenge in getting this layout- the challenge is that I am unable to get that snap effect – AnswerDroid Oct 01 '15 at 06:00
  • @AnswerDroid what snap effect u want to achieve ?? – ch3tanz Oct 01 '15 at 06:07
  • just try to scroll the whatsapp screen that has tabs a bit.. if you will leave it either it will merge with toolbar fully or will not merge at all . you will not be able to get the view( as shown in image above) if you stop scrolling.That is the snap effect I am talking about – AnswerDroid Oct 01 '15 at 06:44
  • Okay I got your point. It doesn't stop at that position where you left scrolling. Let me check the code again. – ch3tanz Oct 01 '15 at 06:51
1

Try this:

<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:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="192dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapseToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="80dp"
            app:expandedTitleMarginStart="30dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="Custom Layout">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                android:src="@drawable/bridge"
                app:layout_collapseMode="pin"
                app:layout_collapseParallaxMultiplier="1.5"/>


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

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

    </android.support.design.widget.AppBarLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="@android:color/holo_blue_dark"
        app:elevation="10dp"
        android:translationZ="10dp"
        android:layout_marginRight="20dp"
        app:layout_anchor="@+id/appBar"
        app:layout_anchorGravity="bottom|right|end"
        app:borderWidth="0dp"
        android:visibility="gone"
        android:src="@drawable/plus" />
    <android.support.v7.widget.RecyclerView
        android:id="@+id/uid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Aakash
  • 5,181
  • 5
  • 20
  • 37
  • I dont have challenge in getting this layout- the challenge is that I am unable to get that snap effect – AnswerDroid Oct 01 '15 at 06:00
  • just try to scroll the whatsapp screen that has tabs a bit.. if you will leave it either it will merge with toolbar fully or will not merge at all . you will not be able to get the view( as shown in image above) if you stop scrolling. am i clear? – AnswerDroid Oct 01 '15 at 06:44