0

For the layout in one of my activities, I have a floating action button on the bottom right. But for some reason, there is no padding on the margins for the button despite setting app:useCompatPadding="true".

Here is the XML code:

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_class_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:src="@drawable/ic_add_white_24dp"
        app:useCompatPadding="true" />

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

</android.support.design.widget.CoordinatorLayout>

And here is an image of the layout: enter image description here

Some help would be appriecated, thanks!

Vineet Patel
  • 477
  • 7
  • 17

3 Answers3

1

Try this

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


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

    <android.support.design.widget.FloatingActionButton
        android:layout_margin="16dp"
        android:id="@+id/add_class_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:useCompatPadding="true" />

</android.support.design.widget.CoordinatorLayout>
Rakesh R
  • 695
  • 7
  • 18
0

The reason is you are not providing margin to it. This should work

 <android.support.design.widget.FloatingActionButton
    android:contentDescription="@string/menu_compose"
    android:id="@+id/add_class_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right|end"
    android:layout_marginBottom="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginEnd="16dp"
    app:useCompatPadding="true"
    android:src="@drawable/ic_add_white_24dp"
    app:fabSize="normal"/>
Saurabh Padwekar
  • 3,888
  • 1
  • 31
  • 37
0

I Hope this will work for you.

Use as given below

<android.support.design.widget.FloatingActionButton
            android:id="@+id/fabImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|bottom"
            android:layout_margin="16dp"
            android:visibility="visible"
            app:backgroundTint="@color/colorAccent"
            app:borderWidth="0dp"
            app:elevation="0dp"
            app:fabSize="normal"
            app:pressedTranslationZ="12dp"
            app:rippleColor="#dadada"
            app:srcCompat="@mipmap/ic_image" />
GParekar
  • 1,209
  • 1
  • 8
  • 15