FloatingActionButton default margin not working in lollipop
A

3

24

I am displaying FloatingActionButton along with a Recyclerview in a CoordinatorLayout, when the FAB is clicked a row would be added in Recyclerview. Now the problem is the FAB has margin when i tested in API 15 but when I test in API 22(lollipop 5.1.1-Nexus 4) I do not get any margin and the FAB is pressed to the edge of the screen.

My concern is FAB has default margin setup in API 15(didnt test other devices) but not in API 22 or am I missing something.

My layout code:

<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:background="#6fbababa"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:paddingBottom="@dimen/fab_padding_bottom"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:orientation="horizontal"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
            ---------------------
            ---------------------    
        </LinearLayout>

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button_floating_action"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/ic_plus"
        app:borderWidth="0dp"
        app:layout_anchor="@id/my_recycler_view"
        app:layout_anchorGravity="bottom|right|end"
        app:rippleColor="@color/wallet_highlighted_text_holo_light" />

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

enter image description here

Aviles answered 15/6, 2015 at 7:24 Comment(2)
#30688388Fic
K based on the link I see its an issue with the library.Aviles
S
21

Just use:

app:useCompatPadding="true"

This should add required space.

Silviasilviculture answered 10/8, 2016 at 12:21 Comment(0)
R
14

I ended up using API-specific margin values. My action button is like this:

    <android.support.design.widget.FloatingActionButton
    android:contentDescription="@string/menu_compose"
    android:id="@+id/action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:src="@drawable/ic_create_white"
    android:layout_gravity="bottom|right|end"
    android:layout_marginBottom="@dimen/action_button_margin"
    android:layout_marginRight="@dimen/action_button_margin"
    android:layout_marginEnd="@dimen/action_button_margin"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    app:fabSize="normal"/>

@dimen/action_button_margin is defined in both values/dimens.xml:

<dimen name="action_button_margin">0dp</dimen>

And in values-v21/dimens.xml:

<dimen name="action_button_margin">16dp</dimen>
Rogation answered 25/7, 2015 at 20:36 Comment(0)
L
0

I presume you have the same Problem as described in this question. The different margin is because of the shadow being calculated or not depending on the API version.

Lovel answered 21/10, 2015 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.