http://debuglog.iteye.com/blog/1441828

  1. Android 2.3.3
  2. Eclipse Version: 3.7.0
  3. LogCat

LogCat  报错信息:

  1. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
  2. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.widget.ScrollView.addView(ScrollView.java:229)
  3. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.rInflate(LayoutInflater.java:627)
  4. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
  5. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
  6. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
  7. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
  8. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
  9. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.Activity.setContentView(Activity.java:1657)
  10. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at com.tmall.nokia.manage.CopyRight.onResume(CopyRight.java:50)
  11. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
  12. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.Activity.performResume(Activity.java:3832)
  13. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
  14. 03-06 11:32:11.126: ERROR/AndroidRuntime(17173): ... 12 more

发生错误原因分析:

ScrollView仅支持一个子项。

查看对应的layout xml

  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent" android:layout_height="wrap_content"
  3. android:scrollbars="vertical">
  4. <TextView android:id="@+id/nokia" android:layout_gravity="center"
  5. android:layout_width="fill_parent" android:layout_height="wrap_content"
  6. android:textAppearance="?android:attr/textAppearanceMedium"
  7. android:text="@string/text_nokia"></TextView>
  8. <TextView android:id="@+id/iphone4s" android:layout_gravity="center"
  9. android:layout_width="wrap_content" android:layout_height="wrap_content"
  10. android:text="@string/text_iphone4s"></TextView>
  11. </ScrollView>

发现ScrollView中有两个TextView子项。

解决办法:

在ScrollView 中设LinearLayout为子项 ,将其它View放入LinearLayout。

  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent" android:layout_height="wrap_content"
  3. android:scrollbars="vertical">
  4. <LinearLayout android:id="@+id/tmall"
  5. android:layout_width="fill_parent" android:layout_height="wrap_content"
  6. android:orientation="vertical">
  7. <TextView android:id="@+id/nokia" android:layout_gravity="center"
  8. android:layout_width="fill_parent" android:layout_height="wrap_content"
  9. android:textAppearance="?android:attr/textAppearanceMedium"
  10. android:text="@string/text_nokia"></TextView>
  11. <TextView android:id="@+id/iphone4s" android:layout_gravity="center"
  12. android:layout_width="wrap_content" android:layout_height="wrap_content"
  13. android:text="@string/text_iphone4s"></TextView>
  14. </LinearLayout>
  15. </ScrollView>

PS。在编辑layout xml时应注意“Error Log”窗口与layout xml编辑窗口的“Graphical Layout”选项卡。

ScrollView不能包含多个子项,ScrollView can host only one direct child的更多相关文章

  1. ScrollView can host only one direct child

    Android 采用ScrollView布局时出现异常:ScrollView can host only one direct child. 异常原因: 主要是ScrollView内部只能有一个子元素 ...

  2. &quot;ScrollView can host only one direct child&quot;问题解决了

    1. 问题叙述性说明: (请注意以下几点大胆). ScrollView作为顶层view时报错,直接导致apk崩溃.具体错误信息例如以下: 12-21 09:12:15.150: D/AndroidRu ...

  3. [Android] ScrollView can host only one direct child

    android 采用ScrollView布局时出现异常:ScrollView can host only one direct child.主要是ScrollView内部只能有一个子元素,即不能并列两 ...

  4. android 异常:ScrollView can host only one direct child

    android 采用ScrollView布局时出现异常:ScrollView can host only one direct child. 主要是ScrollView内部只能有一个子元素,即不能并列 ...

  5. ScrollView:ScrollView can host only one direct child异常

    java.lang.IllegalStateException: ScrollView can host only one direct child 原因是在外面有一个TextView控件,将其删除则 ...

  6. ScrollView can host only one direct child 解决

    主要是ScrollView内部只能有一个子元素,即不能并列两个子元素,所以需要把所有的子元素放到一个LinearLayout内部或RelativeLayout等其他布局方式让后再在这个layout外部 ...

  7. 实现ScrollView中包含ListView,动态设置ListView的高度

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  8. 解决ScrollView中包含ListView,导致ListView显示不全

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  9. android 有弹性的ScrollView 简单实现,与处理ScrollView和ListView,GridView之间的冲突

    处理ScrollView和ListView,GridView之间的冲突, 最好的办法就是继承这两个类,重写他们的onMeasure方法即可: ListView: import android.widg ...

随机推荐

  1. hdu1423LCIS zoj2432 必须掌握!

    LCIS就是最长上升公共子序列,要结合LIS和LCS来求 LIS:f[j]=max(f[i])+1; LCS:f[i,j]=max(f[i-1,j],f[i,j-1]或f[i-1,j-1]+1 那么对 ...

  2. Redis 5.0 集群搭建

    Redis 5.0 集群搭建 单机版的 Redis 搭建 https://www.jianshu.com/p/b68e68bbd725 /usr/local/目录 mkdir redis-cluste ...

  3. Angular2学习(一)

    Angular2的新特性: angular2的核心: 模块.组件.元数据.模板.数据绑定.服务.指令.依赖注入.模块. 组件:层层嵌套,形成组件树.父子组件沟通有输入和输出接口 组件包含JavaScr ...

  4. Windows10 Compatibility Telemetry(CompatTelRunner.exe) 占用硬盘100%

    相信很多人跟我一样总被Compatibility Telemetry(CompatTelRunner.exe) 占用硬盘100%困扰,Compatibility Telemetry翻译过来就是“微软兼 ...

  5. Oracle回收站的清理方法

    http://blog.itpub.net/18841027/viewspace-1057765/

  6. python学习之集合

    集合(set)是一个无序的不重复元素序列. 可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典. 创建格 ...

  7. 基于python的机器学习开发环境安装(最简单的初步开发环境)

    一.安装Python 1.下载安装python3.6 https://www.python.org/getit/ 2.配置环境变量(2个) 略...... 二.安装Python算法库 安装顺序:Num ...

  8. Python读取大文件的"坑“与内存占用检测

    python读写文件的api都很简单,一不留神就容易踩"坑".笔者记录一次踩坑历程,并且给了一些总结,希望到大家在使用python的过程之中,能够避免一些可能产生隐患的代码. 1. ...

  9. redis分布式锁小试

    一.场景 项目A监听mq中的其他项目的部署消息(包括push_seq, status, environment,timestamp等),然后将部署消息同步到数据库中(项目X在对应环境[environm ...

  10. VB.NET 编程元素支持更改总结

    Visual Basic 2005 更改了它支持各种编程元素的方式,主要是为了提供与公共语言运行库的互操作性.许多 Visual Basic 6.0 元素被重新命名,重新分类或与 Visual Bas ...