java - .IllegalStateException: ScrollView 只能承载一个直接子级
问题描述
我非常努力地理解 ScrollView 和 Linearlayout 并不断尝试在我的活动中使用,但我遇到了这个错误。我在滚动视图中已经只有一个 Linearlyout 并且其他孩子被包裹在高度和宽度的包裹内容中但是应用程序仍然崩溃..请帮助
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
tools:context=".Blood">
<TextView
android:layout_width="wrap_content"
android:layout_height="56dp"
android:textStyle="bold"
android:background="#f4051d"
android:textAlignment="center"
android:textColor="#ffffff"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Blood Type: Facts and Information"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:padding="5dp">
<TextView
android:id="@+id/intro"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000000"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="When "/>
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Blood Types ( Groups )"/>
<TextView
android:id="@+id/blood_types"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="A blood "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawable_blood_one"/>
<TextView
android:id="@+id/blood_type_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="In addition ."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Donating Blood By Compatible Type"/>
<TextView
android:id="@+id/donate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="Blood "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawable_blood_two"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Finding Out Your Blood Type"/>
<TextView
android:id="@+id/find_blood_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="It is easy "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/image_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawable_blood_three"/>
<TextView
android:id="@+id/find_blood_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="In most"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="What Does Blood Group RH Factor Mean"/>
<TextView
android:id="@+id/rh_factor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="RH factor ."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="What is the Rarest Blood Type"/>
<TextView
android:id="@+id/rare_blood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="According "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Blood Type Diet"/>
<TextView
android:id="@+id/blood_type_diet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text=" The Ea"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Blood Types and Personality"/>
<TextView
android:id="@+id/personality"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="Legend"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#0e06f2"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Facts: Blood Types"/>
<TextView
android:id="@+id/facts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sans-serif-condensed"
android:text="Blood"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
</ScrollView>
</LinearLayout>
提前致谢。
解决方案
你需要像这样在 ScrollView 中只有一个孩子。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView ... />
<TextView ... />
<TextView ... />
<TextView ... />
</LinearLayout>
</ScrollView>
推荐阅读
- cassandra - 如何按 Cassandra 中的二级索引或列对结果进行排序?
- python - 带有可选文本的电话号码正则表达式,在在线工具上运行良好,但在我的代码中却不行
- excel - 对象'_Workbook'的方法'SaveAs'失败
- amazon-web-services - 为什么集群自动扩缩器不能在 AWS EKS 上运行?
- c++ - 错误:构造函数期望和接收不同数量的参数、预期的主表达式错误和没有匹配的函数
- multithreading - 如何为 Akka HTTP 配置特定的调度程序?
- sql - 存储和检索 SQL Azure 的 SQL 管理员密码
- javascript - 如何创建粘性导航栏?
- javascript - 如何在此数据结构中选择这些成员变量
- java - java pojo中相同的json字段设置为不同的属性