FragmentTabHost图形布局不呈现

Eri*_*wer 40 android android-layout android-support-library android-studio

简单的android.support.v4.app.FragmentTabHost的图形布局永远不会在Eclipse或Android Studio中呈现.
我得到的控制台错误始终如一:
Exception raised during rendering: No tab known for tag null

我正在使用最基本的XML文件:

<android.support.v4.app.FragmentTabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>
Run Code Online (Sandbox Code Playgroud)

但是会发生同样的错误.

我只是想在标签小部件和框架布局的上方或下方添加更多视图.
看到标签内容我并不在意; 我只是想看看我的其余部分 - 但问题是,当 android.support.v4.app.FragmentTabHost 布局中存在时,不会呈现任何其他视图.

我已阅读并尝试从这篇文章的答案中解决问题:
Android:底部带有FragmentTabHost的标签,
但我不认为这是我的问题; 我不打算在底部放一个TabWidget.

我的每个XML文件都完美打开.

Android Studio中出现同样的问题:
Android Studio也不会渲染它

Ali*_*zar 0

不确定......但是您的布局不应该在 tabwidget 的线性布局上方有一个 tabhost 标签吗?

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
>
Run Code Online (Sandbox Code Playgroud)

我不久前制作了一个应用程序,使用 tabhost 实现了选项卡,这就是我的布局...一个选项卡有一个日历视图,一个有一个图像切换器,一个有一个列表视图...抱歉,我无法提供更多帮助

<LinearLayout 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:background="@drawable/background"
tools:context=".MainActivity" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background"
        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/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <ListView
                    android:id="@+id/listView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </ListView>
            </LinearLayout>

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

                <ImageSwitcher
                    android:id="@+id/imageSwitcher1"
                    android:layout_width="match_parent"
                    android:layout_height="251dp" >
                </ImageSwitcher>

                <TextView
                    android:id="@+id/tv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scrollbars="vertical" />

            </LinearLayout>

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

                <CalendarView
                    android:id="@+id/calendarView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>

        </FrameLayout>
    </LinearLayout>

</TabHost>
Run Code Online (Sandbox Code Playgroud)

  • 好吧,常规的 android.widget.TabHost 可以工作,除了 [android.app.TabActivity 已弃用][tabactivity] 转而使用 FragmentTabHosts 和 Fragments。[tabactivity]:[http://developer.android.com/reference/android/app/TabActivity.html] (2认同)