源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-03-20 09:21 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android ScrollView只能添加一个子控件问题解决方法
本文实例讲述了Android ScrollView只能添加一个子控件问题解决方法。分享给大家供大家参考,具体如下: 有下面一段代码
<?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,也许你认为没有什么问题,那么我们运行一下看看 出现了一个异常 [img]http://files.jb51.net/file_images/article/201602/2016224112650121.png?2016124112732[/img] 很明显,异常告诉我们ScrollView can host only one direct child 既然说只能容纳一个直接的子控件,那么我们就可以容纳多个间接的子控件,直接在这些子控件外面再套一层LinearLayout就OK了
<?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相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/410.htm]Android开发入门与进阶教程[/url]》、《[url=http://www.1sucai.cn/Special/398.htm]Android多媒体操作技巧汇总(音频,视频,录音等)[/url]》、《[url=http://www.1sucai.cn/Special/381.htm]Android基本组件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/375.htm]Android视图View技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/371.htm]Android布局layout技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/124.htm]Android控件用法总结[/url]》 希望本文所述对大家Android程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部