浮动操作按钮底部边距不起作用

Ref*_*i0n 1 android margin floating-action-button

我试图在屏幕的右下角实现一个浮动按钮,但由于某种原因下边距不起作用:/我试图仅在底部更改边距大小,但没有用。

布局文件:

活动_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

app_bar_main.xml

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.js_labs.gaminggroups.MainActivity"
android:id="@+id/appBarMainRl">

<include
layout="@layout/some_content" // Changed by LayoutInflater in Java ...
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

some_content.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:useCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp"
android:id="@+id/contentMyGroupsRl"
tools:context=".MainActivity">

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/ic_action_addgroup"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    app:fabSize="normal"
    android:layout_margin="@dimen/fab_margin"
    android:layout_alignParentBottom="true" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

截图: https : //i.stack.imgur.com/COpgF.png

Anu*_*ugh 6

尝试app:useCompatPadding="true"在 FloatingActionButton 标签中添加 ,如下所示:

<android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:layout_marginEnd="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:scaleType="center"
        app:fabSize="mini"
        app:useCompatPadding="true" />
Run Code Online (Sandbox Code Playgroud)