当 BottomAppBar 从隐藏状态返回时,BottomAppBar FabCradleMargin 变得更小,几乎持平

Gee*_*Mpn 4 android android-button floating-action-button android-bottomappbar

当 hideonScroll 设置为 true 时,在我的应用程序中导航并向上/向下滚动时,我的底部应用程序栏中的 FabCradleMargin 变得越来越小,几乎平坦,我遇到了一个问题。当 BottomAppBar 从屏幕上隐藏时,它会在浮动操作按钮下返回调整大小。一定是新的 Android Material 组件中的一个故障。还有其他人遇到过这个问题吗?如果是这样,您有什么建议来解决它。

之前的图像

后像

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    app:elevation="4dp"
    app:fabAlignmentMode="center"
    app:fabCradleRoundedCornerRadius="2dp"
    app:hideOnScroll="true"
    app:layout_scrollFlags="scroll|enterAlways"
    app:navigationIcon="@drawable/ic_action_list" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="@color/blue500"
    app:fabSize="normal"
    app:layout_anchor="@+id/bar"
    app:tint="@color/white"
    app:layout_anchorGravity="right"
    app:srcCompat="@drawable/ic_select_camera" />
Run Code Online (Sandbox Code Playgroud)

Jer*_*tra 5

我也偶然发现了这个问题。就我而言,这取决于我试图隐藏BottomAppBar和 的方式FloatingActionButton。这是我首先拥有的(Kotlin):

private fun showBottomNavigationBar(barVisibility: Boolean, fabVisibility: Boolean) {
    navView.visibility = if (barVisibility) BottomAppBar.VISIBLE else BottomAppBar.GONE
    fab.visibility = if (fabVisibility) FloatingActionButton.VISIBLE else FloatingActionButton.GONE
}
Run Code Online (Sandbox Code Playgroud)

这就是修复它的原因:

private fun showBottomNavigationBar(barVisibility: Boolean, fabVisibility: Boolean) {
    navView.visibility = if (barVisibility) BottomAppBar.VISIBLE else BottomAppBar.GONE
    if (fabVisibility) fab.show() else fab.hide()
}
Run Code Online (Sandbox Code Playgroud)

因此,我没有使用FloatingActionButton可见性属性来隐藏 ,而是使用了 的hide()show()方法FloatingActionButton