ScrollView不能包含多个子项,ScrollView can host only one direct child
http://debuglog.iteye.com/blog/1441828
- Android 2.3.3
- Eclipse Version: 3.7.0
- LogCat
LogCat 报错信息:
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.widget.ScrollView.addView(ScrollView.java:229)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.rInflate(LayoutInflater.java:627)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.Activity.setContentView(Activity.java:1657)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at com.tmall.nokia.manage.CopyRight.onResume(CopyRight.java:50)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.Activity.performResume(Activity.java:3832)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
- 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): ... 12 more
发生错误原因分析:
ScrollView仅支持一个子项。
查看对应的layout xml
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:scrollbars="vertical">
- <TextView android:id="@+id/nokia" android:layout_gravity="center"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:text="@string/text_nokia"></TextView>
- <TextView android:id="@+id/iphone4s" android:layout_gravity="center"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:text="@string/text_iphone4s"></TextView>
- </ScrollView>
发现ScrollView中有两个TextView子项。
解决办法:
在ScrollView 中设LinearLayout为子项 ,将其它View放入LinearLayout。
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:scrollbars="vertical">
- <LinearLayout android:id="@+id/tmall"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView android:id="@+id/nokia" android:layout_gravity="center"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:text="@string/text_nokia"></TextView>
- <TextView android:id="@+id/iphone4s" android:layout_gravity="center"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:text="@string/text_iphone4s"></TextView>
- </LinearLayout>
- </ScrollView>
PS。在编辑layout xml时应注意“Error Log”窗口与layout xml编辑窗口的“Graphical Layout”选项卡。
ScrollView不能包含多个子项,ScrollView can host only one direct child的更多相关文章
- ScrollView can host only one direct child
Android 采用ScrollView布局时出现异常:ScrollView can host only one direct child. 异常原因: 主要是ScrollView内部只能有一个子元素 ...
- "ScrollView can host only one direct child"问题解决了
1. 问题叙述性说明: (请注意以下几点大胆). ScrollView作为顶层view时报错,直接导致apk崩溃.具体错误信息例如以下: 12-21 09:12:15.150: D/AndroidRu ...
- [Android] ScrollView can host only one direct child
android 采用ScrollView布局时出现异常:ScrollView can host only one direct child.主要是ScrollView内部只能有一个子元素,即不能并列两 ...
- android 异常:ScrollView can host only one direct child
android 采用ScrollView布局时出现异常:ScrollView can host only one direct child. 主要是ScrollView内部只能有一个子元素,即不能并列 ...
- ScrollView:ScrollView can host only one direct child异常
java.lang.IllegalStateException: ScrollView can host only one direct child 原因是在外面有一个TextView控件,将其删除则 ...
- ScrollView can host only one direct child 解决
主要是ScrollView内部只能有一个子元素,即不能并列两个子元素,所以需要把所有的子元素放到一个LinearLayout内部或RelativeLayout等其他布局方式让后再在这个layout外部 ...
- 实现ScrollView中包含ListView,动态设置ListView的高度
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- 解决ScrollView中包含ListView,导致ListView显示不全
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- android 有弹性的ScrollView 简单实现,与处理ScrollView和ListView,GridView之间的冲突
处理ScrollView和ListView,GridView之间的冲突, 最好的办法就是继承这两个类,重写他们的onMeasure方法即可: ListView: import android.widg ...
随机推荐
- spring事物的传播行为及隔离
关于@Transactional注解: 添加事务注解1.使用 propagation 指定事务的传播行为, 即当前的事务方法被另外一个事务方法调用时如何使用事务, 默认取值为 REQUIRED, 即使 ...
- 一张纸,折多少次和珠穆拉峰一样高(for if 和break)
- 【转载】如何让图片按比例响应式缩放、并自动裁剪的css技巧
原文: http://blog.csdn.net/oulihong123/article/details/54601030 响应式网站.移动端页面在DIV CSS布局中对于图片列表或图片排版时, 如果 ...
- JS实现数组去重(重复的元素只保留一个)
1.遍历数组法 它是最简单的数组去重方法(indexOf方法) 实现思路:新建一个数组,遍历去要重的数组,当值不在新数组的时候(indexOf为-1)就加入该新数组中: ,,,,,,,,]; func ...
- Sandcastle方法生成c#.net帮助类帮助文档chm
Sandcastle方法生成c#.net帮助类帮助文档即chm后缀的文档,其实是通过C#文档注释生成的XML文件来生成帮助文档的.因此,第一步就是生成XML文档, 步骤1生成XML文档 1.打开VS- ...
- 【splunk】启动停止
在控制台 splunk目录/bin下 ./splunk start #启动 ./splunk stop #停止 启动时出错,需要更改一下SPLUNK的配置 $SPLUNK_HOME/etc/splun ...
- 步步为营-55-js练习
1:加法计算器 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...
- C#读取wav文件
private void showWAVForm(string filepath) //此函数只能用于读取16bit量化单声道的WAV文件 { FileStream fs = new FileStre ...
- python小知识-属性查询优先级(如果有同名类属性、数据描述符、实例属性存在的话,实例>类>数据描述符)
https://www.cnblogs.com/Jimmy1988/p/6808237.html https://segmentfault.com/a/1190000006660339 https:/ ...
- div+css中height:auto !important; height:663px; min-height:663px !important;区别
height:auto !important是高度自适应,主要的是,!important只是对于ie6不认识而已,其他浏览器都是以这个为最高的优先级,执行这个,ie6会无视这个,不是只有火狐而已hei ...