Positioning FloatingActionButton

Asked 2 years ago, Updated 2 years ago, 137 views

Hello! I'm posting a question because I don't know how to change the location of FAB <

Views are arranged as shown above. The FAB in the figure is located in the Coordinator Layout in the Acidity_main.xml file, in the center of the largest square (including the outermost square, red). Um... The center of cell phone screen? You could say that.

By the way, I want to adjust to the red square center right now, but what should I do to do that? Views are located in the content_main.xml file, and are all organized as LinearLayout.

I think... Um... I think you can take the location of that red square and find the center through calculation and set the location to the location of the FAB...

I've seen somewhere that the way to get the location is param, but I haven't used it yet "T" I'm not sure if I can change the location of FAB through param in the Cordinator Layout...

Is this possible? If possible, I think I should study about param<

android floating-action-button

2022-09-22 21:57

2 Answers

Is the red square one? (I don't know if you understand the question correctly.)^ ^ ;)

;)

I think there's only one red square Hold the anchor of Floating Action Button in a red square I think you can give it to layout_anchorGravity as center_vertical|center_horizontal.

    <android.support.design.widget.FloatingActionButton
        ...omission
        app:layout_anchor="@id/red square ID"
        app:layout_anchorGravity="center_vertical|center_horizontal" />


2022-09-22 21:57

I don't know much about Coordinator Layout, but like Linear Layout, child views have layout_gravity property. Try setting FAB's layout_gravity to center.

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />


2022-09-22 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.