【发布时间】:2019-05-14 17:32:17
【问题描述】:
我在HorizontalScrollView 中有一个RecyclerView。我没有看到 RecyclerView 里面的所有项目。我看过,即使适配器中的列表有 7 个项目,onBindViewHolder 也只被调用了 4 次!如果我取出HorizontalScrollView,它可以正常工作。
我使用HorizontalScrollView,因为我需要滚动带有回收背景的列表,而不是在回收内部,它通常是如何工作的。
所以,我需要一个解决方案来滚动带有列表背景的列表,或者使用HorizontalScrollView显示所有项目
更新:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:scrollbars="none"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rlWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/paddingStartView"
android:background="@drawable/bg_round_corner">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/optionsRv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent" />
</RelativeLayout>
<View
android:id="@+id/paddingStartView"
android:layout_width="16dp"
android:layout_height="16dp" />
<View
android:id="@+id/paddingEndView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_toEndOf="@id/rlWrapper" />
</RelativeLayout>
</HorizontalScrollView>
<TextView
android:id="@+id/label"
style="@style/FontLocalizedMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:textAllCaps="true"
android:textColor="#979797"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Tempareature" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
我不明白你想要什么,.....“我需要滚动列表,背景是回收,而不是回收”
-
@ghita 你找到解决办法了吗?我也遇到了同样的问题
-
是的,我会根据回复编辑问题
-
谢谢!我将 HorizontalScrollView 的子项更改为 RelativeLayout,它对我来说非常好
标签: android android-recyclerview horizontalscrollview