2011-05-04 40 views
1

我在TabHost中有一個FrameLayout。我收到以下錯誤。我怎樣才能讓它在Eclipse中呈現?在PostHost過程中出現TabHost錯誤

Error during post inflation process: 
The FrameLayout for the TabHost has no content. Rendering failed. 

這裏是我的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"> 

    <!-- 
    <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/actionbarRelativeLayout"> 
     <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@+id/stocktwitsImageButton"></ImageButton> 
     <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@+id/composeImageButton" android:layout_alignParentRight="true"></ImageButton> 
    </RelativeLayout> 
--> 

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

回答

1

這是摘自Android的源setupTabHost方法:

final int count = content.getChildCount(); 

if (count == 0) { 
    throw new PostInflateException(
      "The FrameLayout for the TabHost has no content. Rendering failed.\n"); 
} 

作爲例外說,你需要有內容。重構XML到:

<FrameLayout android:id="@android:id/tabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/tab1"></LinearLayout> 
</FrameLayout> 
+0

是的,你說得對,這是什麼導致錯誤信息。然而,我(可能還有其他人)在運行期間填寫了這個信息;它添加了更多的代碼,因爲我必須刪除此選項卡。我想這是進步。嘆。 – 2012-08-22 13:41:09

+0

好的,ghost選項卡不顯示(圖形佈局編輯器除外)!酷 - 猜我應該等待,直到我在抱怨前先測試它。 – 2012-08-22 13:51:09