android - float 操作按钮在 API 21 及更高版本中与底部对齐?

标签 android android-layout floating-action-button

我在该代码中使用了 float Action

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".menuscreens.AllRecipientsActivity">

    <GridView
        android:gravity="center"
        android:numColumns="3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gridViewRecipients"
        />

    <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_marginTop="@dimen/action_button_margin"
        android:layout_marginBottom="@dimen/action_button_margin"
        android:layout_marginRight="@dimen/action_button_margin"
        android:layout_marginEnd="@dimen/action_button_margin"
        android:layout_marginLeft="@dimen/action_button_margin"
        android:src="@android:drawable/ic_input_add"
        android:tint="#fff"
        android:id="@+id/fabAddMoreRecipients"
        android:layout_gravity="bottom|right"

        />

</RelativeLayout>

基本上我的问题是,在 API 21 及更高版本中,它没有从底部获得 margin

还有两个屏幕截图,一个来自 bluestack API 19,第二个是 MotoG API 23

API 19 bluestack

API 23 MotoG

最佳答案

像下面这样使用app:useCompatPadding="true"

<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:src="@drawable/icon_add_place"
    app:backgroundTint="@color/colorPrimary"
    app:fabSize="normal"
    app:useCompatPadding="true"/>

关于android - float 操作按钮在 API 21 及更高版本中与底部对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37294288/

相关文章:

android - 在 float 操作按钮中创建菜单

android - 如何在Android中的SearchView中删除屏幕覆盖图?

android - 在右上角设置 ActionBarDrawerToggle

java - float 操作按钮加号未显示

android - 将图像部分放置在工具栏上方

android - DBHelper 无法解析为变量

android - Lollipop 前的 FloatingActionButton 阴影

android - 使用 adb 卸载多个 android 包

android - 改造中的动态路径

java - 拖拽时, stub 中的 ListView 会变黑。