展会信息港展会大全

Android中ScrollView只能添加一个子控件
来源:互联网   发布日期:2015-10-03 10:54:13   浏览:2081次  

导读:有下面一段代码[html] <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schem...

有下面一段代码

[html] <?xml version="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>

<?xml version="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,也许你认为没有什么问题,那么我们运行一下看看

出现了一个异常

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

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

[html] <?xml version="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开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港