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 ...
随机推荐
- Android Studio 超级简单的打包生成apk
为什么要打包: apk文件就是一个包,打包就是要生成apk文件,有了apk别人才能安装使用.打包分debug版和release包,通常所说的打包指生成release版的apk,release版的apk ...
- 常见的js算法
参考地址:链接
- LeetCode(46):全排列
Medium! 题目描述: 给定一个没有重复数字的序列,返回其所有可能的全排列. 示例: 输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [ ...
- codeforce 139E
成段更新+离散化才能过,数据好强.. 单点更新挂在了test27,下次做到成段更新再来做! /* 期望=存活概率*点权值/100 ans=sum(期望) 离散化树木权值,数轴统计累加可能倒下的树木概率 ...
- hdu 1542 线段树+扫描线 学习
学习扫描线ing... 玄学的东西... 扫描线其实就是用一条假想的线去扫描一堆矩形,借以求出他们的面积或周长(这一篇是面积,下一篇是周长) 扫描线求面积的主要思想就是对一个二维的矩形的某一维上建立一 ...
- 浅谈Phoenix在HBase中的应用
一.前言 业务使用HBase已经有一段时间了,期间也反馈了很多问题,其中反馈最多的是HBase是否支持SQL查询和二级索引,由于HBase在这两块上目前暂不支持,导致业务在使用时无法更好的利用现有的经 ...
- CSP 地铁修建 Kruskal (最小生成树+并查集)
问题描述 A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n号枢纽间修建一条地铁. 地铁由很多段隧道组成,每段隧道连接两个交通枢纽.经过勘探,有m段隧道作为候选,两个交通 ...
- CDH搭建Hadoop集群(Centos7)
一.说明 节点(CentOS7.5) Server || Agent CPU node11 Server || Agent 4G node12 Agent 2G node13 Agent 2G 二 ...
- window.location方法获取URL
window.location方法获取URL 统一资源定位符 (Uniform Resource Locator, URL) 完整的URL由这几个部分构成: scheme://host:port/pa ...
- Centos7与Windows10添加Windows10启动项并设置为默认启动
在Centos7下root登陆 编辑 /boot/grub2/grub.cfg vim /boot/grub2/grub.cfg 在第一行添加 menuentry "Windows10&qu ...