手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android ScrollView只能添加一个子控件问题解决方法
Android ScrollView只能添加一个子控件问题解决方法
摘要:本文实例讲述了AndroidScrollView只能添加一个子控件问题解决方法。分享给大家供大家参考,具体如下:有下面一段代码一个Scrol...

本文实例讲述了Android ScrollView只能添加一个子控件问题解决方法。分享给大家供大家参考,具体如下:

有下面一段代码

<"1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> </LinearLayout>

一个ScrollView里面添加了三个Button,也许你认为没有什么问题,那么我们运行一下看看

出现了一个异常

Android ScrollView只能添加一个子控件问题解决方法1

很明显,异常告诉我们ScrollView can host only one direct child

既然说只能容纳一个直接的子控件,那么我们就可以容纳多个间接的子控件,直接在这些子控件外面再套一层LinearLayout就OK了

<"1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> </LinearLayout>

希望本文所述对大家Android程序设计有所帮助。

【Android ScrollView只能添加一个子控件问题解决方法】相关文章:

android开发环境遇到adt无法启动的问题分析及解决方法

android图库竖屏不显示status bar的解决方法

Android上使用jspf插件框架的方法

Android 获取进程内存使用情况方法

Android拍照保存在系统相册不显示的问题解决方法

android ListView自动滚动方法

popupwindow焦点问题解决方案

Android View添加 Listener 实例代码

Android笔记之:在ScrollView中嵌套ListView的方法

android 微信 sdk api调用不成功解决方案

精品推荐
分类导航