开发者

Tabhost tutorial broken? [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Anyone know what this error mean for android tabs?

I have been trying to do the TabHost tutorial in the SDK but for some reason, is appears to break. On Step 4 I copy and paste the xml code, I get an error that prevents it from inflating properly. the error is:

 Error in an XML file: aborting build.

This is in the graphical layout of the xml file.

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'

The xml file Itself has this in it.

    <?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>开发者_StackOverflow中文版;

Am I doing something wrong?


Use this template:

<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>


See step 5 , your Activity must extend TabActivity, not Activity

Now open HelloTabWidget.java and make it extend TabActivity:


Switch to android target 3.0 or 3.1 in the graphical layout itself. You can find the drop down list on the top right corner


You can use the updated rendering library found here: Android Tools.

Just extract the directories found in \layoutlib\[platform version] to \[sdk dir]\platforms\[platform version] and let it override the layoutlib.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜