Juliatzin del Toro Juliatzin del Toro - 5 months ago 74
Android Question

Bottom Align Floating Action Button

I want to align to bottom right my FAB.


  1. I tried with
    android:gravity="bottom|right"

  2. When I try
    android:layout_alignParentBottom="true
    "
    FAB
    disappear

  3. When I try
    android:layout_alignBottom="@id/lista_tiendas"
    FAB
    disappear



It doesn't seems complicated but I just can't do it :(

Any Idea?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

<ListView
android:id="@+id/lista_tiendas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="4.0sp"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_48dp"
app:backgroundTint="@color/spg_rosa"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="@id/lista_tiendas"
/>
</RelativeLayout>

Answer

Please make sure that your layout type is RelativeLayout, and then:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    app:fabSize="normal"
    ... />

If the FAB is placed in CoordinatorLayout, you should use android:layout_gravity="end|bottom"

See this answer for more information.