作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 RecyclerView
在 HorizontalScrollView
内.我看不到里面 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>
最佳答案
使 HorizontalScrollView
的 child 成为 RelativeLayout
而不是 LinearLayout
关于android - HorizontalScrollView 内的 RecyclerView 不显示所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56135717/
我是一名优秀的程序员,十分优秀!