I am using CollapsingToolBarLayout alongside with AppBarLayout and CoordinatorLayout, and they are working Fine altogether. I set my <
Here is the solution in Kotlin:
abstract class AppBarStateChangeListener : OnOffsetChangedListener {
enum class State {
EXPANDED, COLLAPSED, IDLE
}
private var mCurrentState =
State.IDLE
override fun onOffsetChanged(appBarLayout: AppBarLayout, i: Int) {
mCurrentState = if (i == 0) {
if (mCurrentState != State.EXPANDED) {
onStateChanged(appBarLayout, State.EXPANDED)
}
State.EXPANDED
} else if (Math.abs(i) >= appBarLayout.totalScrollRange) {
if (mCurrentState != State.COLLAPSED) {
onStateChanged(appBarLayout, State.COLLAPSED)
}
State.COLLAPSED
} else {
if (mCurrentState != State.IDLE) {
onStateChanged(appBarLayout, State.IDLE)
}
State.IDLE
}
}
abstract fun onStateChanged(
appBarLayout: AppBarLayout?,
state: State?
)
}
Here is the listener:
appbar.addOnOffsetChangedListener(object : AppBarStateChangeListener() {
override fun onStateChanged(
appBarLayout: AppBarLayout?,
state: State?
) {
if(state == State.COLLAPSED){
LayoutBottom.visibility = View.GONE
}else if(state == State.EXPANDED){
LayoutBottom.visibility = View.VISIBLE
}
}
})