FloatingActionButton with BottomNavigationView

前端 未结 2 1841
执念已碎
执念已碎 2021-02-14 08:48

I cant position my FAB. It should be bottom right, but on top of the BottonNavigationView.

1) Can i achieve this without RelativeLayout inside coordinateLayout?

2条回答
  •  深忆病人
    2021-02-14 09:47

    A quick search to FloatingActionButton.Behavior tells us the following thing.

    @Override
    public void onAttachedToLayoutParams(@NonNull CoordinatorLayout.LayoutParams lp) {
        if (lp.dodgeInsetEdges == Gravity.NO_GRAVITY) {
            // If the developer hasn't set dodgeInsetEdges, lets set it to BOTTOM so that
            // we dodge any Snackbars
            lp.dodgeInsetEdges = Gravity.BOTTOM;
        }
    }
    

    Since BottomNavigationView also resides at the bottom of the layout. Add following element to your BottomNavigationView and CoordinatorLayout will handle the inset and dodging for you automatically.

    app:layout_insetEdge="bottom"
    

提交回复
热议问题