【问题标题】:FloatingActionButton is not pinning in RecyclerViewFloatingActionButton 未固定在 RecyclerView 中
【发布时间】:2021-03-17 10:17:21
【问题描述】:

我想每次都显示FloatingActionButton 右下角(同时滚动)。但是当我将它与RecyclerView 一起使用时,它不会显示在RecyclerView 上。它显示在RecyclerView 下方。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    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"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/kitapListeRw"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/kitapEkleBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:clickable="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        app:srcCompat="@drawable/ic_add_24dp" />

 </androidx.coordinatorlayout.widget.CoordinatorLayout>

如何每次都显示FAB右下角而不是RecyclerView下方?

【问题讨论】:

  • 不确定我是否正确理解了您的问题,但请尝试将您的 RecyclerView 包装在 ScrollView 中。
  • 我想固定 FAB。即使滚动recyclerview。

标签: android android-recyclerview floating-action-button coordinator-layout


【解决方案1】:

尝试为父级设置底部和结束约束

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/kitapEkleBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:clickable="true"
    android:layout_marginBottom="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginEnd="10dp"
    app:srcCompat="@drawable/ic_add_24dp" />

【讨论】:

  • 似乎这是要走的路+1
  • @Zain 首先感谢您的编辑。但很遗憾没有置顶。
  • @emreturka 感谢您的评论,请问您是否设置了mRecyclerView.addOnScrollListener? ..也许你不小心把工厂藏在上面
  • @emreturka 这个解决方案有什么意想不到的结果?
【解决方案2】:

好的,我解决了这个问题。我犯了一个错误的建筑。我把浮动按钮放在我的主布局中。因为有一个drawerlayout。

【讨论】:

    猜你喜欢
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2018-01-09
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多