FloatingActionButton 高于 BottomAppBar [英] FloatingActionButton too high over BottomAppBar

查看:37
本文介绍了FloatingActionButton 高于 BottomAppBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 API 28 向 BottomAppBar 添加了一个 FAB,如下面的 XML 所示.问题是它漂浮在底部栏上方太高而不是坐在摇篮中.如果我将 app:fabCradleVerticalOffset 设置为 0dp,则没有任何变化.

I added a FAB to a BottomAppBar from API 28 like in the XML below. The problem is that it floats too high above the bottom bar instead of sitting in the cradle. There is no change if I set app:fabCradleVerticalOffset to 0dp.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:paddingTop="30dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_gravity="bottom"
        app:backgroundTint="@android:color/white"   
        app:fabAlignmentMode="center" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabIncrement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_exposure_plus_1_black_24dp"
        app:backgroundTint="@color/colorPrimary"
        app:fabSize="normal"
        app:layout_anchor="@id/bottomAppBar" />

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

推荐答案

这似乎是 BottomAppBar 的一个错误(或者可能是一个功能).FAB 的垂直偏移取决于BottomAppBar 的高度;如果您将 layout_height 设置为 48dp,它会很好地放置在摇篮中.另一方面,如果您将高度设置为 200dp,您将看到 FAB 更远.

This appears to be a bug (or maybe a feature) of BottomAppBar. The vertical offset of the FAB is dependent on the height of the BottomAppBar; if you set layout_height to be 48dp instead, it will sit very nicely in the cradle. On the other hand, if you set the height to be 200dp you'll see that the FAB is even farther away.

另外(不幸的是),app:fabCradleVerticalOffset 必须是正值.如果您尝试使用负值(将 FAB 向下推),应用程序将在运行时崩溃.

Additionally (and unfortunately), app:fabCradleVerticalOffset must be a positive value. If you try to use a negative value (to push the FAB down), the app will crash when it runs.

我没有看到任何可以让您解决此问题的公共 API.相反,您只需为 BottomAppBar 使用较小的高度.也许您可以将两个视图拼接在一起以模拟更高的条形.

I don't see any public API that will let you solve this. Instead you'll just have to use a smaller height for your BottomAppBar. Perhaps you'll be able to stitch two views together to simulate a taller bar.

这篇关于FloatingActionButton 高于 BottomAppBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆