Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent CollapsingToolbarLayout collapse if not needed

Using:

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

With the project Cheesesquare updated.

Into the detail of cheese, I remove 2 cards (to have only one). Is there a way to prevent the collapsing of the toolbar that show a blank space?

enter image description here

like image 312
stankocken Avatar asked Aug 29 '15 16:08

stankocken


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 collapsing toolbar Android?

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

To implement such behaviour in Cheesesquare example just modify android:layout_height param of the NestedScrollView to wrap_content. It will prevent scrolling by content if it is small enough to fit on the screen.

And to prevent scrolling by CollapsingToolbarLayout you should programmatically set layout_scrollFlags parameter to the AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP value.

Here described how you can do this.

like image 197
DmitryArc Avatar answered Sep 23 '22 06:09

DmitryArc