How to make Android support floatingactionbutton in the lower right corner of the screen?

I added a floatingactionbutton to the layout in relativelayout, as shown below

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_ok" />

</RelativeLayout>

As you can see, I've put layout_ Gravity is set to bottom | right, but the position of my floatingactionbutton has not changed. It is located in the upper left corner

How can I make my floatingactionbutton in the lower right corner?

resolvent:

Use coordinatorlayout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:id="@+id/test"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</RelativeLayout>

<android.support.design.widget.FloatingActionButton
    android:layout_margin="10dp"
    android:id="@+id/myFAB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="#FF0000"
    app:borderWidth="0dp"
    app:elevation="8dp"
    app:layout_anchor="@id/test"
    app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>

be careful

   app:layout_anchor="@id/test"
   app:layout_anchorGravity="bottom|right|end"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>