Android材质组件底部的应用栏已切断

时间:2018-11-16 22:27:17

标签: android android-layout material-design floating-action-button android-bottomappbar

我已尝试按照以下准则实施材料组件底部的应用栏,并重构到AndroidX +更新我的AppTheme。 Material components - bottom app bar

到目前为止,一切正常,但是按钮在我的片段中被切断了。 Screenshot when app is running

但是xml预览显示了这一点,似乎一切都很好: enter image description here

这是我的xml代码:

<androidx.coordinatorlayout.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"
android:fitsSystemWindows="true">

<!-- Other components and views -->

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottombar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:elevation="2dp"
    app:fabAlignmentMode="center"
    app:fabCradleVerticalOffset="10dp"
    app:fabCradleMargin="10dp" />


<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|center_horizontal"
    android:adjustViewBounds="true"
    app:layout_anchor="@id/bottombar"
    app:layout_anchorGravity="top|center"
    app:srcCompat="@drawable/marker" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

我什至增加了fabCradleMarginfabCradleOffset-否则按钮完全在底部,并且根本不应该悬浮在该半圆内...

有人对此有任何线索吗?非常感谢!

1 个答案:

答案 0 :(得分:0)

因此,我注意到这与底部应用栏的高度有关。如果我手动将其设置为80dp,则Fab将按预期显示。

我尝试了一些,发现此手动高度设置仅在片段中是必需的。我只将底部的应用程序条放在一个片段中以进行测试。 因此,现在我以与MainActivity中的准则相同的方式来实现它,然后设置一个函数showFab(Boolean enable),然后可以根据需要在不同的片段中对其进行调用。

如果有人面对相同的问题,那么它就像一个魅力。我想这可能是因为它不应该仅在单个片段中实现。