Android Tabhost教程坏了吗?

Android Tabhost教程坏了吗?,android,xml,tabs,android-tabhost,Android,Xml,Tabs,Android Tabhost,可能重复: 我一直在尝试在SDK中编写TabHost教程,但由于某些原因,它似乎被破坏了。在步骤4中,我复制并粘贴了xml代码,得到了一个错误,它阻止了xml代码的正确膨胀。错误是: Error in an XML file: aborting build. 这在xml文件的图形布局中 Error during post inflation process: TabHost requires a TabWidget with id "android:id/tabs", View found

可能重复:

我一直在尝试在SDK中编写TabHost教程,但由于某些原因,它似乎被破坏了。在步骤4中,我复制并粘贴了xml代码,得到了一个错误,它阻止了xml代码的正确膨胀。错误是:

 Error in an XML file: aborting build.
这在xml文件的图形布局中

Error during post inflation process:
TabHost requires a TabWidget with id "android:id/tabs",
View found with id "tabs" is 'com.android.layoutlib.bridge.MockView'
xml文件本身就包含这一点

    <?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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <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"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

我做错什么了吗

使用此模板:

<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:id="@+id/tab"    android:orientation="vertical"        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/tab1" android:layout_width="fill_parent"
             android:layout_height="fill_parent" android:orientation="vertical"/>

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

</FrameLayout>
</LinearLayout>
</TabHost>

请参见步骤5,您的活动必须扩展TabActivity,而不是Activity

现在打开HelloTabWidget.java并使其扩展TabActivity:


您可以使用此处找到的更新的呈现库:


只需将
\layoutlib\[platform version]
中的目录提取到
\[sdk dir]\platforms\[platform version]
,并让它覆盖图形布局本身中的
layoutlib

切换到android目标3.0或3.1即可。您可以在右上角找到下拉列表

您是将此作为测试项目还是其他项目运行?看起来选项卡视图类正在被
com.android.layoutlib.bridge.MockView
覆盖。我以前从未见过这个错误。没有测试项目。我甚至不知道com.android.layoutlib.bridge.MockView在哪里。但愿我能。是同一个问题的答案。在尝试了raybritton发布的内容后,我得到了这个错误:错误!RuntimeException:无法创建选项卡内容,因为找不到id为的视图-1@TiagoAfonso仅供参考,我刚刚提交了一份Android工具文件。这似乎对错误没有任何影响。只是澄清一下,我是最新版本(ADT 16.0.1)。我从1.5版一直到4.0.2版都在尝试构建目标,但总是会出现这个错误。