ScrollView不能包含多个子项,ScrollView can host only one direct child
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”选项卡。
相关推荐
JayFighting 2020-06-04
XDgaozhan 2013-07-10
luoj 2011-08-17
AndroidGA 2015-03-22
fuzhangandroid 2012-02-03
PiYuqing 2016-12-26
zzqLivecn 2016-08-15
RickyLee 2015-07-26
superxlcr 2015-03-22
ZhongGuanGuan 2014-10-31
yarkey0 2014-10-22
翟浩浩Android 2014-02-24
OuNuo0 2013-08-05
PrisonJoker 2013-07-10
zmmzmm 2013-01-25
fanjunjian 2012-10-18
housezhu 2012-10-15
yuyu00 2012-05-07