Java Android TabHost不显示

Java Android TabHost不显示,java,android,android-tabhost,Java,Android,Android Tabhost,以下是布局文件: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_paren

以下是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="hk.teawood.httpwww.t_factory.stock_list"
    android:id="@android:id/tabhost">

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

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

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

                <LinearLayout
                    android:id="@+id/linearLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"></LinearLayout>

                <LinearLayout
                    android:id="@+id/linearLayout2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"></LinearLayout>

                <LinearLayout
                    android:id="@+id/linearLayout3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"></LinearLayout>
            </FrameLayout>
        </LinearLayout>

</TabHost>
我只是在布局中添加了一个TabHost,预期的布局应该是这样的:

但结果是,显示了一个空白活动:

如何解决这个问题?

我遵循了以下帖子:

并稍微修改了代码:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hk.teawood.httpwww.t_factory.stock_list">

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

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:tag="tab0"
                android:text="Lend Items" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:tag="tab0"
                android:text="Free Items" />
        </TabWidget>

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


            <ListView
                android:id="@+id/ListViewId2"
                android:layout_width="366dp"
                android:layout_height="match_parent" />
            <ListView
                android:id="@+id/ListViewId"
                android:layout_width="366dp"
                android:layout_height="match_parent" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

现在它开始工作了


如果这就是您正在运行的代码,那么您的所有视图都是空的和透明的。@MikeM。那么我如何使视图不透明??我正在尝试将选项卡页面添加到activityWell,首先,如果您想让LinearLayouts成为您的选项卡,那么它们应该位于
标记中。此外,默认情况下,线性布局是透明的。如果需要颜色,请为每个颜色指定
背景
属性。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hk.teawood.httpwww.t_factory.stock_list">

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

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:tag="tab0"
                android:text="Lend Items" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:tag="tab0"
                android:text="Free Items" />
        </TabWidget>

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


            <ListView
                android:id="@+id/ListViewId2"
                android:layout_width="366dp"
                android:layout_height="match_parent" />
            <ListView
                android:id="@+id/ListViewId"
                android:layout_width="366dp"
                android:layout_height="match_parent" />
        </FrameLayout>
    </LinearLayout>
</TabHost>