1

我有一个底部应用栏:

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottomBar"
    android:layout_gravity="bottom"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    node:backgroundTint="?attr/toolbar"
    node:fabAlignmentMode="end"/>

还有一个 FAB 按钮

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fabAddUser"
    android:src="@drawable/add_user"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    node:backgroundTint="?android:attr/colorAccent"
    node:fabSize="normal"
    node:layout_anchor="@id/bottomBar"
    node:rippleColor="?android:attr/colorPrimaryDark"
    node:tint="@color/white"/>

当屏幕右下角出现 fab 按钮时,一切正常。我的菜单项位于屏幕左侧。当用户滚动菜单项时隐藏 fab 按钮时,菜单项会移动到手机的右侧。当 FAB 按钮改变状态时,让菜单从左向右移动真的很烦人。有什么方法可以让我的菜单项按钮始终位于底部应用栏的左侧。

提前致谢!

编辑#1

我在布局中有一个 ID 为 userList 的回收站视图。我正在使用此代码来隐藏 fab 按钮

userList.addOnScrollListener(object: RecyclerView.OnScrollListener() {
        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {

            // What Happens When The User Is Scrolling Down//
            if (dy > 0) fabAddUser.hide()

            // What Happens When The User Is Scrolling Up//
            else fabAddUser.show()

            // Differ Action To Parent Class//
            super.onScrolled(recyclerView, dx, dy)
        }
    })
4

0 回答 0