Here is the result.

For example code https://github.com/msquare097/MFlex-toolbar , ....
First of all, a good question and very interesting ... and for its implementation.
I used the minimum height of the toolbar by changing the scroll in the viewpager.
First of all, declare all Toolbar heights relative to fragments in your activity where ViewPager implemented.
I just take it directly as an Integer . You load it from dimen as DP and convert it to PX. In my ViewPager I took 4 fragments. So, we declare 4 toolbar heights.
int heightForPage0 = 150; int heightForPage1 = 400; int heightForPage2 = 300; int heightForPage3 = 600;
After configuring the adapter, just add a listener
mViewPager.addOnPageChangeListener(this);
and override all these three methods and write the code below.
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { Log.d(TAG,positionOffset+""); int currentHeight; int nextHeight; switch (position) { case 0: currentHeight = heightForPage0; nextHeight = heightForPage1; calculateHeightAndApply(currentHeight, nextHeight, positionOffset); break; case 1: currentHeight = heightForPage1; nextHeight = heightForPage2; calculateHeightAndApply(currentHeight, nextHeight, positionOffset); break; case 2: currentHeight = heightForPage2; nextHeight = heightForPage3; calculateHeightAndApply(currentHeight, nextHeight, positionOffset); break; case 3:
and here is the magic method that I called onPageScrolled ..
private void calculateHeightAndApply(int currentHeight, int nextHeight, float positionOffset) { if (positionOffset==0) { return; } int diff = nextHeight - currentHeight; int newHeight = (int) ((positionOffset*diff)); mToolbar.setMinimumHeight(currentHeight+newHeight); }