java.lang.IllegalStateException:ScrollView只能承载一个直接子级
我只是想通过添加一个scrollview来添加滚动浏览这个布局的功能,但是每次尝试加载布局时,我都会收到一个错误,声明“java.lang.IllegalStateException:scrollview只能承载一个直接子级”,我不确定为什么 任何建议都将不胜感激 资料来源:java.lang.IllegalStateException:ScrollView只能承载一个直接子级,java,android,xml,android-layout,android-ui,Java,Android,Xml,Android Layout,Android Ui,我只是想通过添加一个scrollview来添加滚动浏览这个布局的功能,但是每次尝试加载布局时,我都会收到一个错误,声明“java.lang.IllegalStateException:scrollview只能承载一个直接子级”,我不确定为什么 任何建议都将不胜感激 资料来源: 编辑(响应CodeMagic的回答) 正如错误所说 ScrollView can host only one direct child 将视图s包装在线性布局中,以便滚动视图仅将线性布局作为直接子视图 Scrol
编辑(响应CodeMagic的回答)
正如错误所说
ScrollView can host only one direct child
将视图
s包装在线性布局
中,以便滚动视图
仅将线性布局
作为直接子视图
ScrollView是一个框架布局,这意味着您应该在其中放置一个子元素,其中包含要滚动的全部内容;此子对象本身可能是具有复杂对象层次结构的布局管理器。通常使用的子项是垂直方向的线性布局,表示用户可以滚动的顶级项的垂直数组
//当前在ScrollView中的所有视图
我尝试使用建议的方法(我在上面发布了我的尝试),但在这样做时,我最终出现了两个错误:方向错误?未指定方向,默认为水平,但此布局有多个子级,其中至少一个子级的layout\u width=“match\u parent”XML文档结构必须在同一实体中开始和结束。是的,抱歉,我忽略了这一点。您需要将方向添加到线性布局中。我已经编辑过了。如果你以后有时间的话,我还有一个简单的问题,你可以帮忙解决。。。此帖子已经有了it解决方案:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtubeplayerview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="1dp"
android:layout_height="5dp" >
</View>
<TextView
android:id="@+id/textView1a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Isaac Daniel at CNN Anderson Cooper"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="by idconex"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView3a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="675,000,000 views"
android:textAppearance="?android:attr/textAppearanceSmall" />
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtubeplayerview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rage Against The Machine - Bulls on Parade"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="by RATMVEVO"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView3b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1,195,601 views"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
ScrollView can host only one direct child
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// all the views currently in your ScrollView
</LinearLayout>
</ScrollView>