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 ...
随机推荐
- html中子界面与父界面相互操作或传值
一.在使用iframe的页面,要操作这个iframe里面的DOM元素可以用: contentWindow.contentDocument(测试的时候chrom浏览器,要在服务器环境下) content ...
- 【转载】如何让图片按比例响应式缩放、并自动裁剪的css技巧
原文: http://blog.csdn.net/oulihong123/article/details/54601030 响应式网站.移动端页面在DIV CSS布局中对于图片列表或图片排版时, 如果 ...
- python 全栈开发,Day88(csrf_exempt,ES6 快速入门,Vue)
BBS项目内容回顾 1. 登陆页面 1. 验证码 1. PIL(Pillow) 2. io 2. ORM 1. 增删改查 3. AJAX $.ajax({ url: '', type: '', dat ...
- python 全栈开发,Day53(jQuery的介绍,jQuery的选择器,jQuery动画效果)
js总结 js: 1.ECMAScript5 ES5语法 2.DOM CRUD 获取 3种方式 id tag className //面向对象 对象 : 属性和方法 某个对象中 function $( ...
- 二.hadoop环境搭建
目录: 目录见文章1 文章:官方文档hadoop2.7.4 目的 这篇文档的目的是帮助你快速完成单机上的Hadoop安装与使用以便你对Hadoop分布式文件系统(HDFS)和Map-Reduce框架有 ...
- HTTP协议特点
1 HTTP协议特点 1)客户端->服务端(请求request)有三部份 a)请求行--请求行用于描述客户端的请求方式.请求的资源名称,以及使用的HTTP协议版本号 请 ...
- 《转》Web Service实践之——开始XFire
Web Service实践之——开始XFire 一.Axis与XFire的比较XFire是与Axis2 并列的新一代WebService平台.之所以并称为新一代,因为它:1.支持一系列Web Serv ...
- Delphi---TServerSocket和TClientSocket发送和接收大数据包
https://www.cnblogs.com/zhangzhifeng/p/6065244.html TServerSocket和TClientSocket用非阻塞模式发送和接收比较大的数据时,可能 ...
- Zookeeper笔记(三)部署与启动Zookeeper
下载zookeeper安装包 去Zookeeper官网,下载地址http://zookeeper.apache.org/releases.html,建议下载稳定版本,我下载的是zookeeper-3. ...
- KNN分类算法实现手写数字识别
需求: 利用一个手写数字“先验数据”集,使用knn算法来实现对手写数字的自动识别: 先验数据(训练数据)集: ♦数据维度比较大,样本数比较多. ♦ 数据集包括数字0-9的手写体. ♦每个数字大约有20 ...