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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

炫_愛羊   2021-03-20 我要评论
想了解Android ScrollView只能添加一个子控件问题解决办法的相关内容吗,炫_愛羊在本文为您仔细讲解Android ScrollView只能添加一个子控件问题解决办法的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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,也许你认为没有什么问题,那么我们运行一下看看

出现了一个异常

很明显,异常告诉我们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程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们