android - Position FloatingActionButton programmatically in center of CoordinatorLayout -


there coordinatorlayout:

<android.support.design.widget.coordinatorlayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/cl_root"     android:layout_width="match_parent"     android:layout_height="match_parent"> </android.support.design.widget.coordinatorlayout> 

question: how 1 create , position programmatically floatingactionbutton in center of screen?


important:: floatingactionbutton created programmatically only (no need post answers define in xml file).

floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); coordinatorlayout.layoutparams lp = (coordinatorlayout.layoutparams) fab.getlayoutparams(); lp.anchorgravity = gravity.center // or can add gravity.center_vertical | gravity.center_horizontal fab.setlayoutparams(lp); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -