1

有两个 RadioButton、十二个复选框和一个发送按钮,每个按钮都有一个自定义选择器。RadioButton 和 Checkbox 超出范围,不能让所有 RadioButton 和 Checkbox 在 android xml 布局中。我使用了 ScrollView,但它有一些关于“渲染期间引发异常:ScrollView 只能托管一个直接子级”的错误。我不知道 RadioButton 和 Checkbox 的范围如何。如何将 RadioButton 和 CheckBox 更改为该范围内的 RadioButton?谢谢。

在此处输入图像描述

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


       <ScrollView
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          >


       <TextView
           android:id="@+id/etIdUserName2"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:textSize="10sp" />

       <TextView
           android:id="@+id/etIdUseracc2"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:textSize="10sp" />

       <TextView
            android:id="@+id/etIdPassre2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="10sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="使用者性別"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/boy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男" />

        <RadioButton
            android:id="@+id/girl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="使用者年齡"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="20sp" />

        <CheckBox
            android:id="@+id/under"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="18以下"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/between2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="23~27"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/between1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="18~23"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/between3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="28~32"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/up"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="32以上"
            android:textSize="15sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="使用者興趣"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="20sp" />

        <CheckBox
            android:id="@+id/girluse"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="女裝與服飾配件、女包精品與女鞋"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/makeup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="美容保養與彩妝"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/boyuse"
            android:layout_width="152dp"
            android:layout_height="wrap_content"
            android:text="男性精品與服飾"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/electronicproduct"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="電腦、平板與周邊"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cellphone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="手機、配件與通"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/food"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="美食與地方特產"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/Stationery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="文具與事務用"
            android:textSize="15sp" />

        <Button
            android:id="@+id/setbutton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="送出"
            android:textSize="15sp" />

             </ScrollView>
</LinearLayout>
4

2 回答 2

2

“ScrollView 只能托管一个直接子级”。

因此,只需将所有内容包装在LinearLayout.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


       <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          >


       <TextView
           android:id="@+id/etIdUserName2"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:textSize="10sp" />

       <TextView
           android:id="@+id/etIdUseracc2"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:textSize="10sp" />

       <TextView
            android:id="@+id/etIdPassre2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="10sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="使用者性別"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="20sp" />

        <RadioButton
            android:id="@+id/boy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男" />

        <RadioButton
            android:id="@+id/girl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="使用者年齡"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="20sp" />

        <CheckBox
            android:id="@+id/under"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="18以下"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/between2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="23~27"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/between1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="18~23"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/between3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="28~32"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/up"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="32以上"
            android:textSize="15sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="使用者興趣"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="20sp" />

        <CheckBox
            android:id="@+id/girluse"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="女裝與服飾配件、女包精品與女鞋"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/makeup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="美容保養與彩妝"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/boyuse"
            android:layout_width="152dp"
            android:layout_height="wrap_content"
            android:text="男性精品與服飾"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/electronicproduct"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="電腦、平板與周邊"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cellphone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="手機、配件與通"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/food"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="美食與地方特產"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/Stationery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="文具與事務用"
            android:textSize="15sp" />

        <Button
            android:id="@+id/setbutton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="送出"
            android:textSize="15sp" />

        </LinearLayout>
</ScrollView>
于 2014-05-11T06:42:46.773 回答
1

根据 Logcat 所说Exception raised during rendering: ScrollView can host only one direct child。一个人只能有一个直接子视图ScrollView。因为你有这么多的复选框和 RadioButton 里面ScrollView会抛出一个错误。

你只需要在ParentView 中添加你所有的Checkboxand ,因为它可以处理你所有的and 。在这里,我已经添加了所有你的and 。RadioButtonViewScrollViewRadioButtonCheckboxesLinearlayoutParentViewCheckboxesRadioButton

解释:

ScrollView // ParentView
   LinearLayout // DirectChild of ScrollView
      RadioButton & Checkboxes // Direct child of LinearLayout

布局:

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >
   <ScrollView
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
   <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
    >
   <TextView
       android:id="@+id/etIdUserName2"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:textSize="10sp" />

   <TextView
       android:id="@+id/etIdUseracc2"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:textSize="10sp" />

   <TextView
        android:id="@+id/etIdPassre2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="使用者性別"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="20sp" />

    <RadioButton
        android:id="@+id/boy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="男" />

    <RadioButton
        android:id="@+id/girl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="女" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="使用者年齡"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="20sp" />

    <CheckBox
        android:id="@+id/under"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="18以下"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/between2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="23~27"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/between1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="18~23"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/between3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="28~32"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="32以上"
        android:textSize="15sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="使用者興趣"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="20sp" />

    <CheckBox
        android:id="@+id/girluse"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="女裝與服飾配件、女包精品與女鞋"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/makeup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="美容保養與彩妝"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/boyuse"
        android:layout_width="152dp"
        android:layout_height="wrap_content"
        android:text="男性精品與服飾"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/electronicproduct"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="電腦、平板與周邊"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/cellphone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="手機、配件與通"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/food"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="美食與地方特產"
        android:textSize="15sp" />

    <CheckBox
        android:id="@+id/Stationery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="文具與事務用"
        android:textSize="15sp" />

    <Button
        android:id="@+id/setbutton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="送出"
        android:textSize="15sp" />
      </LinearLayout>
      </ScrollView>
  </LinearLayout>
于 2014-05-11T06:42:28.263 回答