I need to be able to change the app:layout_anchorGravity="center"
of the FAB from center
to bottom|start
from the code.
I've found this example:
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(xxxx);
fab.setLayoutParams(p);
but it's for setting the anchor and not the anchor gravity.
From a design perspective, there are two ways of anchoring a FAB: Inset: The shape of the BottomAppBar is transformed to allow the FAB to be “cradled” (at the same elevation) within a cutout. This is the default behavior. Overlap: The FAB is simply positioned over the BottomAppBar (at a higher elevation) and has no effect on the shape.
D D I D Dynamic Design for Anchors page 20 Dynamic Design for Anchors ΔV Rd,c : Concrete edge design resistance at c min • concrete C20/25 1) The design value of the ultimate state in shear is calculated from the characteristic anchor shear resistance,
You can anchor a Floating Action Button (FAB) to BottomAppBar by specifying the id of the BottomAppBar in app:layout_anchor attribute of the FAB. BottomAppBar can cradle FAB with a shaped background or FAB can overlap BottomAppBar.
Floating Action Button (FAB) in Android with Example. The floating action button is a bit different button from the ordinary buttons. Floating action buttons are implemented in the app’s UI for primary actions (promoted actions) for the users and the actions under the floating action button are prioritized by the developer.
The CoordinatorLayout.LayoutParams
class has the anchorGravity
field for that. For example:
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
lp.anchorGravity = Gravity.BOTTOM | GravityCompat.START;
fab.setLayoutParams(lp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With