I'm trying to achieve the toolbar and User image animation like the one that is used in Twitter's user profile.
I tried a lot of things but I cannot achieve pinning the collapsed toolbar at the top of the screen quickly with the some background it had when it was expanded and making the User Image be first above the toolbar and then make a scale down and move below the toolbar while scrolling.
How does twitter make the smooth effect in the User Profile image? How they first have this image in front of the toolbar and then while scrolling goes behind and achieve that smooth effect going below the toolbar?
I tried all the following scenarios:
- Toolbar with parallax effect with CollapseParallaxMultiplier.
- Pin Toolbar setting height 100dp and minHeight ?attr/actionBarSize.
- 2 Toolbars, one with the image background and the other one pinning it with transparent background color.
- Scalling UserImage and then moving the Y position (cannot achieve effect that send the User Image below the toolbar when scrolling) smoothly.
None of the previous scenarios worked well for me.
XML hierarchy:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout>
<!--Some TextViews and ImageViews-->
</LinearLayout>
<ImageView src="My User profile Img"/> <!--Image first above toolbar and when toolbar is collapsing scale down and then go below toolbar-->
<ImageView src="My background" app:layout_collapseMode="parallax" app:layout_collapseParallaxMultiplier="0.8"/>
<android.support.v7.widget.Toolbar app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--Second Part, where the ViewPager should be pinned below the Toolbar-->
<NestedScrollView app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout>
<android.support.design.widget.TabLayout/>
<android.support.v4.view.ViewPager/>
</LinearLayout>
</NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Attached you can see the Twitter effect on the user profile activity.