I have a coordinator layout containing a collapsing toolbar, a nestedscrollview and a floating button. My floating button is placed at the bottom right end of the collapsing too
Setting offset listener to the toolbar would give you more flexibility: you'd be able to decide what would happen when the toolbar has collapsed / opened.
appBarLayout.addOnOffsetChangedListener(
AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
if (verticalOffset == 0) {
showFAB()
// logic when toolbar is open (for example show fab)
} else {
hideFAB()
// logic when toolbar has collapsed (for example hide fab)
})
If case you'd like to know whenever toolbar is in between / you need the java code: https://stackoverflow.com/a/39424318/11878751