1

我想在每个选项卡中使用多个CheckBox,但即使我在 LinearLayout 下有三个框,也只有一个框显示在选项卡中。

我也为每个复选框设置了 ID。

这是正在使用的代码。

主文件

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/widget43"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:orientation="vertical"
             >

            <CheckBox
                android:id="@+id/root"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Tortillas" />

            <CheckBox
                android:id="@+id/root1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Tortillas1" />

            <CheckBox
                android:id="@+id/roo2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Tortillas2" />

        </LinearLayout>

    </FrameLayout>

</TabHost>
4

2 回答 2

0

我认为您需要将 CheckBox 的宽度和高度更改为“wrap_content”而不是“fill_parent”。第一个填充父母,其余的没有任何东西。

编辑

将 LinearLayout 的高度也更改为 wrap_content (看看我自己的一些,这就是我设置它们的方式)。

于 2012-06-11T14:42:17.440 回答
0

除了@Barak,您还缺少 TabHost 之后的线性布局

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:id="@+id/widget43"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <CheckBox
                    android:id="@+id/root"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Tortillas" />

                <CheckBox
                    android:id="@+id/root1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Tortillas1" />

                <CheckBox
                    android:id="@+id/roo2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Tortillas2" />
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>

</TabHost>
于 2012-06-11T15:19:09.490 回答