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 ...
随机推荐
- Linear Algebra(未完待续)
[矩阵消元] The result of multiplying a matrix by some vector is a combination of the columns of the matr ...
- Luogu P4945 【最后的战役】
本来以为做法一样,就是少带个$log$,结果发现看不懂出题人的题解(我好菜啊) 那就自己写一篇吧 比较简单的$DP$思路 状态定义: 前两个转移很好处理,第三个好像就不好办了 不妨暴力定义进状态里 设 ...
- Luogu P3294 【[SCOI2016]背单词】
阅读理解题 ...... $Trie$ 后缀问题不好处理,我们把它转化为前缀问题,用字典树解决问题 贪心 容易想到,一个串的后缀要先于它插入 对于一个串和其若干后缀串,容易想到,我们要先插入后缀串 然 ...
- cf1108e 线段树区间更新+扫描线
/* 有点像扫描线 思路:从左到右枚举每个点,枚举到点i时,把所有以i为起点的区间的影响删去 再加上以i-1为结尾的区间的影响 */ #include<bits/stdc++.h> usi ...
- hdu3966 树链剖分点权模板+线段树区间更新/树状数组区间更新单点查询
点权树的模板题,另外发现树状数组也是可以区间更新的.. 注意在对链进行操作时方向不要搞错 线段树版本 #include<bits/stdc++.h> using namespace std ...
- 利用setTimeout延时器 制作广告自动关闭
模仿广告自动关闭效果 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- ruby学习--条件控制
条件控制 本人喜欢用程序demo记录的方式来记录某方法的使用,如times方法,仅作个人学习记录 #--------------if语句(相反是unless)而while相同于until------- ...
- day8--socketserver回顾
sockeserver主要实现多并发的情况,我们知道,socket只能一对一用户进行交互,如何实现一对多交互,socketserver就是用来解决这个问题的. socketserver--共有这么几种 ...
- python_cookbook之路:数据结构-解压可迭代对象赋值给多个变量以及扩展的迭代解压语法(*)
1.一一对应: >>> data = [ 'ACME', 50, 91.1, (2012, 12, 21) ] >>> name, shares, price, d ...
- vue中mixin的一点理解
vue中提供了一种混合机制--mixins,用来更高效的实现组件内容的复用.最开始我一度认为这个和组件好像没啥区别..后来发现错了.下面我们来看看mixins和普通情况下引入组件有什么区别? ...