1

I am using this technique for creating multiple snapping points on collapsing toolbar (I use same layout and code)

But my question is how can I show the toolbar when user scrolls up at the middle of the recyclerview

Currently if user reaches the top, it shows the toolbar first, after that it expands collapsing toolbar

But I want to show the toolbar when user scrolls up at the middle of the recyclerview (before reaching top), after that, if user reaches the the top I want to expand collapsing layout.

How can I modify that answer for achive that?

Currently it looks like this. I want to show only the toolbar when user scrolls up if user reaches to top I want to show all collapsing toolbar

enter image description here

My AppBarLayout

        <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/app_bar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:background="@color/colorPrimary"
                app:elevation="0dp"
                android:elevation="0dp">


            <com.google.android.material.appbar.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    app:layout_scrollFlags="scroll|snap"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="@dimen/app_bar_expanded_title_margin_start">

                <LinearLayout
                        android:id="@+id/expanded_layout"
                        android:visibility="visible"
                        android:layout_width="match_parent"
                        android:layout_height="200dp"
                        android:layout_marginBottom="?attr/actionBarSize"
                        android:orientation="vertical">


                </LinearLayout>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

            <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="90dp"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    android:layout_gravity="bottom"
                    app:layout_collapseMode="pin"
                    android:contentInsetLeft="0dp"
                    android:contentInsetStart="0dp"
                    app:contentInsetLeft="0dp"
                    app:contentInsetStart="0dp"
                    android:contentInsetRight="0dp"
                    android:contentInsetEnd="0dp"
                    app:contentInsetRight="0dp"
                    app:contentInsetEnd="0dp">
                <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">
                ...
                </LinearLayout>
            </androidx.appcompat.widget.Toolbar>

            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    android:layout_marginStart="@dimen/general_margin"
                    android:orientation="horizontal">


                <CustomTabLayout
                        android:id="@+id/tab_layout"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/discover_tab_height"
                        android:background="@color/colorPrimary"
                        android:paddingEnd="@dimen/general_margin"
                        android:layout_gravity="center"
                        android:clipToPadding="false"
                        app:tabMode="scrollable"
                        app:tabGravity="fill"
                        app:tabBackground="@drawable/discover_tab_selector"
                        android:elevation="@dimen/tab_layout_elevation"
                        app:tabSelectedTextColor="@color/colorPrimary"
                        app:tabTextColor="@color/colorAccentPassive"
                        app:tabRippleColor="@null"
                        app:tabIndicatorHeight="0dp"
                        app:tabMinWidth="30dp"
                        app:tabIndicatorColor="@color/transparent"
                        app:tabTextAppearance="@style/DiscoverTabTextAppearance"/>
            </LinearLayout>

        </com.google.android.material.appbar.AppBarLayout>

plese check the link CoordinatorLayout with multiple snapping points

Thank you and sorry for my english.

Emre Akcan
  • 982
  • 10
  • 27
  • You can use collapsing toolbar ...checkout https://www.journaldev.com/13927/android-collapsingtoolbarlayout-example – Santanu Sur Aug 20 '19 at 14:42
  • @SantanuSur that is what I'm using, please go to link that I referred. – Emre Akcan Aug 20 '19 at 14:43
  • I am confused with this line "I want to show only the toolbar when user scrolls up if user reaches to top I want to show all collapsing toolbar" Would you please explain what you really want in detail ? – AgentP Aug 20 '19 at 15:18
  • if user reaches the top, it must be behave like on the gif @PraveenPanishetti, important point is if user scrolls up at the middle of the recyclerview toolbar must be shown not whole collapsingtoolbar. – Emre Akcan Aug 20 '19 at 15:20

0 Answers0