Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop scroll on CollapsingToolbarLayout so it doesn't completely collapse

Tags:

I have a CollapsingToolbarLayout setup and im placing a wallpaper there. I want to be able to stop it from collapsing all the way.

I have tried minheight and many other things but can't figure it out.

How can i get it to stop collapsing to the second screenshot?

View when activity is loaded

Loaded View

Desired Stopping Point

Desired Stopping point

Current Stopping Point

Current Stopping Point

like image 291
BigDX Avatar asked Jul 23 '15 21:07

BigDX


People also ask

How do I stop my toolbar from collapsing?

The solution is simple, we just need to set the app:scrimAnimationDuration=”0" in our collapsing toolbar layout like the below code snippet. Now just run the code and see the results, you will see then there will be no fading animation anymore.

What is CollapsingToolbarLayout?

CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout .


1 Answers

CollapsingToolbarLayout works really closely with Toolbar and as such the collapsed height depends on the toolbar.

I was able to solve your problem using this layout (Note it goes into the normal CoordinatorLayout/AppBarLayout Setup, With Fab and a NestedScrollView or RecyclerView):

<android.support.design.widget.CollapsingToolbarLayout     android:id="@+id/collapsing_toolbar"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitsSystemWindows="true"     app:layout_scrollFlags="scroll|exitUntilCollapsed"     app:statusBarScrim="?attr/colorPrimaryDark"     app:contentScrim="@android:color/transparent"     app:titleEnabled="false"     >     <!-- There isnt a contentSCrim attribute so the toolbar is transparent after being          collapsed          Disabled the title also as you wont be needing it -->      <ImageView         android:id="@+id/image_v"         android:layout_width="match_parent"         android:layout_height="360dp"         android:layout_gravity="center"         android:scaleType="centerCrop"         android:src="@drawable/md2"         android:fitsSystemWindows="true"         app:layout_collapseMode="parallax"         tools:ignore="ContentDescription"         />         <!-- Normal Imageview. Nothing interesting -->      <android.support.v7.widget.Toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="168dp"         app:layout_collapseMode="pin"         app:popupTheme="@style/ThemeOverlay.AppCompat.Light"         />         <!-- The toolbar is styled normally. However we disable the title also in code.         Toolbar height is the main component that determines the collapsed height -->      <TextView         android:text="@string/app_name"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="bottom"         android:background="?attr/colorPrimaryDark"         android:paddingLeft="72dp"         android:paddingRight="0dp"         android:paddingBottom="24dp"         android:paddingTop="24dp"         android:textColor="@android:color/white"         android:textAppearance="@style/TextAppearance.AppCompat.Headline"         />         <!-- The title textView -->  </android.support.design.widget.CollapsingToolbarLayout> 

The related activity looks like this:

    ...     setSupportActionBar((Toolbar) findViewById(R.id.toolbar));     getSupportActionBar().setDisplayHomeAsUpEnabled(true);      // Disable toolbar title     getSupportActionBar().setDisplayShowTitleEnabled(false);     ... 

Here's a video of the interaction

enter image description here

like image 158
efemoney Avatar answered Sep 23 '22 17:09

efemoney