Armen  Apresyan
Armen Apresyan

Reputation: 65

floating action button at bottom right

I'm using this xml, which contains a single ListView and a Floating Action Button. I want the FAB to always be at bottom right(but not too close to borders of screen) but it just fits the list's last item(so when the list has a single item, it's getting at top right)

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

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/simpleRems"
        android:dividerHeight="0dp"
        android:divider="@null"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true" />

    <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>

Upvotes: 3

Views: 4355

Answers (1)

Wilder Pereira
Wilder Pereira

Reputation: 2267

Try setting your SwipeMenuListView height to match_parent and remove your test relative layout.

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

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/simpleRems"
        android:dividerHeight="0dp"
        android:divider="@null"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true" />


    <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"
        android:layout_gravity="bottom|right"
        app:layout_anchor="@id/simpleRems"
        app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>

Upvotes: 5

Related Questions