Hide floating button when collapsing toolbar is collapsed

前端 未结 2 2381
长情又很酷
长情又很酷 2021-02-20 02:46

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

相关标签:
2条回答
  • 2021-02-20 03:15

    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

    0 讨论(0)
  • 2021-02-20 03:20

    Try this small change

    <android.support.design.widget.FloatingActionButton
        ...
        app:layout_anchor="@id/appBar"
        app:layout_anchorGravity="bottom|right|end" />
    
    0 讨论(0)
提交回复
热议问题