android - 将recyclerview的滚动条放在父布局android的末尾

标签 android android-recyclerview

我有以下布局。目前,滚动条位于箭头布局上方,但我需要将滚动条放置在布局底部,即箭头布局下方。我尝试在 Recyclerview 中使用 scrollbarStyle 但没有成功。关于如何克服这个问题有什么建议吗?

enter image description here

我的布局:

<androidx.constraintlayout.widget.ConstraintLayout
          android:id="@+id/itemLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:gravity="center"
          android:minHeight="@dimen/size_94dp"
          android:visibility="gone"
          android:clickable="true"
          bind:layout_constraintEnd_toEndOf="@+id/listLayout"
          bind:layout_constraintStart_toStartOf="parent"
          android:background="@color/white"
          bind:layout_constraintTop_toBottomOf="@+id/listLayout"
          >

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="@dimen/size_0dp"
            android:orientation="horizontal"
            android:scrollbars="horizontal"
            android:scrollbarStyle="outsideInset"
            android:fadeScrollbars="false"
            bind:layout_constraintStart_toStartOf="parent"
            bind:layout_constraintTop_toTopOf="parent"
            bind:layout_constraintEnd_toEndOf="parent"
            bind:layout_constraintBottom_toTopOf="@+id/arrow_layout"
            android:scrollbarThumbHorizontal="@drawable/custom_scrollbar"
            bind:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            />

        <FrameLayout
            android:id="@+id/arrow_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            bind:layout_constraintBottom_toBottomOf="parent"
            bind:layout_constraintStart_toStartOf="parent"
            bind:layout_constraintEnd_toEndOf="parent"
            >
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
            android:src="@drawable/ic_chevron_left_black_24dp"
              android:adjustViewBounds="true"/>
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/ic_chevron_right_black_24dp"
              android:layout_gravity="end"/>
        </FrameLayout>


      </androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

您已经有了一个约束布局,该布局已设计为可以轻松重叠项目。在这种情况下,最简单的解决方法是在 RV 底部添加填充,然后限制箭头与填充区域重叠

与上面的一些评论相反,这种方法没有任何问题 - 当您不添加新的预定义行为时,自定义 View (或自定义布局管理器)会显得矫枉过正,并且会花费更多的工作。如果您仍然想采用这种方法,您将需要一个搜索栏和回收器一起工作,这对我来说听起来像是引入错误的简单方法

编辑:它应该像添加 android:paddingBottom="25dp" 到 RecyclerView 项目布局的 View 一样简单(传递给 ViewHolder 的布局),然后将 FrameLayout 更改为:

<FrameLayout
        android:id="@+id/arrow_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        bind:layout_constraintBottom_toBottomOf="@id/recyclerView"
        bind:layout_constraintStart_toStartOf="@id/recyclerView"
        bind:layout_constraintEnd_toEndOf="@id/recyclerView"
        android:marginBottom="16dp">

正如 Barotia 提到的,您可以随时将 25dp 和 16dp 更改为您想要的任何值,包括百分比

关于android - 将recyclerview的滚动条放在父布局android的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57728348/

相关文章:

android - 如何使用sqlite创建Kotlin登录名?

Android:在 View 上应用模糊效果 (BlurMaskFilter)

android - 如何滚动到 recyclerview 内的偏移量?

android - soundPool.load上下文问题

android - 如何在 MapView 上实现 OnClickListener

android - 多次使用复合组件时在屏幕旋转时保存状态

android - 当回收者想要回收一个适配器时调用哪个 Recycler Adapter 方法

android - 当 Recyclerview 中的 Edittext 滚出屏幕时隐藏键盘

类似 Gmail 的 Android 5 RecyclerView

java - 解析 JSON 数据时不显示任何内容