Tabhost tutorial broken? [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

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>

Am I doing something wrong?

回答1:

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>


回答2:

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

Now open HelloTabWidget.java and make it extend TabActivity:



回答3:

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



回答4:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!