我有多个LinearLayouts,它们的组合高度很容易超过设备的屏幕高度。因此,为了使布局可滚动,我尝试添加ScrollView,但不幸的是,出现以下错误:
Caused by: android.view.InflateException: Binary XML file line #37: ScrollView can host only one direct child
<?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:orientation="vertical"
android:layout_height="match_parent"
tools:context=".viewbill">
<LinearLayout
android:layout_height="40dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="2"
tools:ignore="MissingConstraints">
<TextView
android:id="@+id/text_1"
android:layout_width="157dp"
android:text="Product"
android:textColor="#000"
android:textSize="18sp"
android:gravity="center"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:id="@+id/text_2"
android:text="Rate"
android:gravity="center"
android:layout_width="163dp"
android:textSize="18sp"
android:textColor="#000"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="@+id/iid"
android:layout_marginTop="45dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center"
android:textColor="#000"
android:textSize="15sp"
tools:ignore="MissingConstraints,NestedWeights" />
</ScrollView>