Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set FAB anchor gravity dynamically

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.

like image 431
Matrucci Avatar asked Jun 26 '16 14:06

Matrucci


People also ask

How do I anchor a fab to the bottomappbar?

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.

What is the dynamic design for anchors?

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,

How to anchor a Floating Action Button to bottomappbar in Android?

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.

What is Floating Action Button (Fab)?

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.


1 Answers

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);
like image 128
Mike M. Avatar answered Nov 22 '22 11:11

Mike M.