【问题标题】:Error during post inflation process for TabHostTabHost 后膨胀过程中的错误
【发布时间】:2011-05-04 00:42:20
【问题描述】:

我在 TabHost 中有一个 FrameLayout。我收到以下错误。如何让它在 Eclipse 中呈现?

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>

【问题讨论】:

    标签: java android eclipse android-tabhost android-framelayout


    【解决方案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>
    

    【讨论】:

    • 是的,你没看错,这就是导致错误消息的原因。但是我(可能还有很多其他人)在运行时填写它;这会添加更多代码,因为我必须删除此选项卡。我想这就是进步。叹息。
    • 好的,ghost 选项卡不显示(图形布局编辑器除外)!很酷——我想我应该等到我先测试后才抱怨。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    相关资源
    最近更新 更多