FragmentTabHost图形布局不会呈现 [英] FragmentTabHost graphical layout doesn't render

查看:491
本文介绍了FragmentTabHost图形布局不会呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的android.support.v4.app.FragmentTabHost图形布局从未呈现在Eclipse或Android的工作室。
控制台的错误我得到的是一致的:
异常渲染过程中提出的:没有标签出名的空标签

我使用的是最基础的XML文件:

 < android.support.v4.app.FragmentTabHost
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

    <的LinearLayout
        机器人:方向=垂直
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>

        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:方向=横向
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =0/>

        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =0dp
            机器人:layout_height =0dp
            机器人:layout_weight =0/>

        <的FrameLayout
            机器人:ID =@ + ID / realtabcontent
            机器人:layout_width =match_parent
            机器人:layout_height =0dp
            机器人:layout_weight =1/>

    < / LinearLayout中>
< /android.support.v4.app.FragmentTabHost>
 

但同样的错误发生。

我只是想补充的上面或下面的标签控件和框架布局更多的意见。
我不那么在乎看到标签的内容;我只是想看到的我的布局的其余部分的 - 但问题是,没有其他意见呈现时, android.support.v4.app .FragmentTabHost 驻留在布局

我已经阅读并试图从这个问题的答案后解决该问题:
<一href="http://stackoverflow.com/questions/13408709/android-tabs-at-the-bottom-with-fragmenttabhost">Android:与FragmentTabHost
标签底部 但我不认为这是我的问题;我不希望把一个TabWidget底部。

我的XML文件每隔一个完全打开。

同样的问题也发生在Android的工作室:

解决方案

我有同样的渲染问题,以及编译错误

。我通过查找,我是不及格片段时,我是创造Addtab解决了这一问题。你必须通过用于至少一个片段上mTabHost.addTab。下面是工作code。

私人FragmentTabHost mTab​​Host; mTabHost =(FragmentTabHost)findViewById(android.R.id.tabhost);             mTabHost.setup(HomeActivity.this,getSupportFragmentManager(),android.R.id.tabcontent);             mTabHost.addTab(mTabHost.newTabSpec(家)setIndicator(家),HomeFragment.class,空);             mTabHost.addTab(mTabHost.newTabSpec(mysheets)setIndicator(MySheets)。);             mTabHost.addTab(mTabHost.newTabSpec(书签)setIndicator(书签));

The graphical layout for a simple android.support.v4.app.FragmentTabHost never renders in either Eclipse or Android Studio.
The Console error I get is consistently:
Exception raised during rendering: No tab known for tag null

I'm using the most basic XML file:

<android.support.v4.app.FragmentTabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>

but the same error occurs.

I just wanted to add more views above or below the tab widget and frame layout.
I don't care so much about seeing the tab content; I just want to see the rest of my layout - but the problem is that NO OTHER VIEWS are rendered when a android.support.v4.app.FragmentTabHost resides in the layout.

I've read and tried to resolve the issue from the answer to this post:
Android: Tabs at the bottom with FragmentTabHost
but I don't think that that is my problem; I'm not looking to put a TabWidget on the bottom.

Every other one of my XML files opens perfectly.

The same problem occurs in Android Studio:

解决方案

I had the same rendering problem as well as compilation error. I fixed the problem by finding that I was not passing Fragment when i was creating Addtab. You must pass atleast one fragment on mTabHost.addTab. Below is the working code.

private FragmentTabHost mTabHost;
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
            mTabHost.setup(HomeActivity.this, getSupportFragmentManager(), android.R.id.tabcontent);

            mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("Home"), HomeFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("mysheets").setIndicator("MySheets"));
            mTabHost.addTab(mTabHost.newTabSpec("bookmarks").setIndicator("Bookmarks"));

这篇关于FragmentTabHost图形布局不会呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆