FloatingActionButton doesn't hide

后端 未结 17 926
星月不相逢
星月不相逢 2020-11-30 03:42

I am trying to hide my FloatingActionButton fabLocation programmatically with :

fabLocation.setVisibility(View.GONE)

but it do

17条回答
  •  离开以前
    2020-11-30 04:29

    here is simple solution

    private var fabAnchorId: Int = View.NO_ID
    private val fabParams: CoordinatorLayout.LayoutParams
            get() = (fab.layoutParams as CoordinatorLayout.LayoutParams)
    
    fun showFab() {
        fabParams.anchorId = fabAnchorId
        fabParams.gravity = Gravity.NO_GRAVITY
        fab.show()
    }
    
    fun hideFab() {
        fabParams.anchorId = View.NO_ID
        fabParams.gravity = Gravity.END.or(Gravity.BOTTOM)
        fab.hide()
    }
    

    before show/hide we have to change anchor and gravity

提交回复
热议问题