Android FloatingActionButton默认边距在棒棒糖中不起作用

Android FloatingActionButton默认边距在棒棒糖中不起作用,android,floating-action-button,androiddesignsupport,android-coordinatorlayout,coordinator-layout,Android,Floating Action Button,Androiddesignsupport,Android Coordinatorlayout,Coordinator Layout,我正在显示FloatingActionButton以及Recyclerview中的CoordinatorLayout,单击晶圆厂时,将在Recyclerview中添加一行。现在的问题是,当我在API 15中测试时,晶圆厂有余量,但当我在API 22(棒棒糖5.1.1-Nexus 4)中测试时,我没有任何余量,晶圆厂被压到屏幕边缘 我担心的是,FAB在API 15中有默认的余量设置(没有测试其他设备),但在API 22中没有,或者我遗漏了什么 我的布局代码: <android.support

我正在显示
FloatingActionButton
以及
Recyclerview
中的
CoordinatorLayout
,单击晶圆厂时,将在
Recyclerview
中添加一行。现在的问题是,当我在API 15中测试时,晶圆厂有余量,但当我在API 22(棒棒糖5.1.1-Nexus 4)中测试时,我没有任何余量,晶圆厂被压到屏幕边缘

我担心的是,FAB在API 15中有默认的余量设置(没有测试其他设备),但在API 22中没有,或者我遗漏了什么

我的布局代码:

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

---------------------
---------------------    

我最终使用了API特定的边距值。我的操作按钮如下所示:

    <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"/>
在values-v21/dimens.xml中:

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

我猜您的问题与中描述的相同。不同的边距是因为阴影的计算与否取决于API版本。

只需使用:

app:useCompatPadding="true"

这应该会增加所需的空间。

K根据链接,我发现它与库有关。