user299648 user299648 - 4 months ago 16
Android Question

How do I make a floating indicator appear at the bottom right corner of a listView?

How do I make a floating indicator appear at the bottom right corner of a listView?

For some reason the code below has the floating indication appear or the top left corner of the listView.

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout"
android:fitsSystemWindows="true"
android:orientation="vertical">

<include layout="@layout/toolbar_general"/>

<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contacts_list_view" />

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

</RelativeLayout>

</LinearLayout>

Answer

Problem is with gravity property you used in floatingActionButton... android:gravity sets the gravity of the content within the View not the View itself. instead...you should use alignParentBottom and alignParentRight properties to get desired result... like this...

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

hope this help...