【问题标题】:Displaying the button in recycler view with distance feature使用距离功能在回收站视图中显示按钮
【发布时间】:2021-08-01 15:39:34
【问题描述】:

我想制作一个类似于附图中的功能。它将在回收器视图顶部显示一个按钮,其中包含回收器视图中项目的距离。当用户向下滚动时,它将显示远离用户位置的项目。但是,我不知道如何实现这种与回收器视图重叠的按钮。谁能告诉我这个功能是什么?我怎样才能搜索更多关于它的信息。我尝试使用“按钮重叠回收器视图”进行搜索,但没有发现任何帮助。任何帮助将不胜感激。谢谢

【问题讨论】:

  • 从你的解释看来,你想实现一个浮动动作按钮!!!!这个 UI 已经存在于 android studio 中
  • 谢谢@Bristol 我找到了。非常感谢你

标签: android android-studio android-recyclerview


【解决方案1】:

这叫做Extended Floating Action Button,你可以这样做:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    >

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:listitem="@android:layout/simple_list_item_checked"
        />

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Displaying items 250 to 500 miles from you"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

输出是:

你也可以看看

Buttons Floating Action Button 还有另一种方法:https://stackoverflow.com/a/61055155/4385913

【讨论】:

  • 我已经编辑了答案,所以你有更多选择
  • 谢谢,我也去看看 :)
猜你喜欢
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 2020-08-07
  • 1970-01-01
  • 2015-02-26
  • 1970-01-01
相关资源
最近更新 更多