I want to implement scroll behavior for Toolbar title as its implemented in Apple Music Android app.
Detailed screenshots of its behaviour: Initial State, Start scrolling, Continue Scrolling, End of scroll
Thank you in advance!
As Piyush said, https://github.com/brucetoo/Android-ObservableScrollView is exactly the library you need for this. This is how you'd go about it
Import the library by going to your app's Gradle file and pasting this
implementation 'com.github.ksoichiro:android-observablescrollview:1.5.0'
Make your xml layout and instead of using a standard ScrollView
to wrap it, use an ObservableScrollView
. Outside of the scroll view, make a toolbar that will host your menu buttons as well as the title i.e. "Library"
In you Java/ Kotlin file, attach a listener to the scroll view by using listView.setScrollViewCallbacks
. Provide an object implementing the ObservableScrollViewCallbacks
interface as an argument.
In the callback, change the YTranslation and alpha values of the title in your toolbar based on the scroll factor
I don't have android studio in front of me, so I can't provide any code, but this is the jist of it.