gpt4 book ai didi

android - Horizo​​ntalScrollView 内的 RecyclerView 不显示所有项目

转载 作者:行者123 更新时间:2023-12-03 22:46:35 29 4
gpt4 key购买 nike

我有一个 RecyclerViewHorizontalScrollView 内.我看不到里面 RecyclerView所有的项目。我看过,即使适配器中的列表有 7 项,onBindViewHolder只调用了 4 次!如果我取出 HorizontalScrollView ,它工作正常。

我使用 HorizontalScrollView因为我需要在回收的背景下滚动列表,而不是在回收内部,它通常是如何工作的。

enter image description here

所以,我需要一个解决方案来滚动列表背景,或者使用 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>

最佳答案

使 HorizontalScrollView 的 child 成为 RelativeLayout而不是 LinearLayout

关于android - Horizo​​ntalScrollView 内的 RecyclerView 不显示所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56135717/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com