【发布时间】:2023-02-22 05:28:39
【问题描述】:
如何使用 RecyclerView 而不是 ScrollView? ScrollView 给我错误,所以我想使用 RecyclerView 而不是 ScrollView。
这是我的第一个片段布局代码:
<?xml version="1.0" encoding="utf-8"?\>
<ScrollView 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:id="@+id/homeF"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/androidbackground2"
tools:context=".ui.home.HomeFragment">
<androidx.constraintlayout.widget.ConstraintLayout
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">
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
当我想从这个布局移动到下面的布局时:
<?xml version="1.0" encoding="utf-8"?\>
<ScrollView 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="match_parent"
android:background="@drawable/androidbackground2">
<androidx.constraintlayout.widget.ConstraintLayout
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">
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
我收到这样的错误:
java.lang.IllegalStateException: ScrollView can host only one direct 孩子
由于此 ScrollView 错误,我无法切换布局。如何解决这个问题?
【问题讨论】:
标签: java android android-recyclerview scrollview