Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android FragmentTabHost图形布局不';不渲染_Android_Android Layout_Android Studio_Android Support Library - Fatal编程技术网

Android FragmentTabHost图形布局不';不渲染

Android FragmentTabHost图形布局不';不渲染,android,android-layout,android-studio,android-support-library,Android,Android Layout,Android Studio,Android Support Library,简单的android.support.v4.app.FragmentTabHost的图形布局不会在Eclipse或android Studio中呈现。 我得到的控制台错误是一致的: 呈现过程中引发异常:没有标记null的已知选项卡 我使用的是最基本的XML文件: <android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" android:

简单的android.support.v4.app.FragmentTabHost的图形布局不会在Eclipse或android Studio中呈现。
我得到的控制台错误是一致的:
呈现过程中引发异常:没有标记null的已知选项卡

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

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

但我不认为这是我的问题;我不想在底部放一个TabWidget

我的每一个XML文件都可以完美地打开

Android Studio中也出现同样的问题:

不确定。。。。但是你的布局不应该在tabwidget的线性布局之上有一个tabhost标记吗

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
>

不久前,我制作了一个应用程序,使用tabhost实现了选项卡,这就是我的布局……一个选项卡有日历视图,一个有图像切换器,一个有列表视图……抱歉,我帮不上什么忙

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <ListView
                    android:id="@+id/listView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </ListView>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <ImageSwitcher
                    android:id="@+id/imageSwitcher1"
                    android:layout_width="match_parent"
                    android:layout_height="251dp" >
                </ImageSwitcher>

                <TextView
                    android:id="@+id/tv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scrollbars="vertical" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <CalendarView
                    android:id="@+id/calendarView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>

        </FrameLayout>
    </LinearLayout>

</TabHost>


不确定您所遇到的错误(对不起,我现在很忙,所以不能花更多时间检查),但一般来说,来自support libs的
FragmentTabHost
似乎根本不关心xml。请参阅我先前对另一个问题的回答:


从布局中,我得到了相同的错误。因此,我仅通过代码解决该问题…它工作正常。请尝试此代码

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class DetailFragment extends Fragment {

    /******************************************************************************************************************
     * Mandatory empty constructor for the fragment manager to instantiate the fragment (e.g. upon screen orientation changes).
     *****************************************************************************************************************/
    public DetailFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // R.layout.fragment_tabs_pager contains the layout as specified in your question
        View rootView = inflater.inflate(R.layout.fragment_tabs_pager, container, false);

        // Initialise the tab-host
        FragmentTabHost mTabHost = (FragmentTabHost) rootView.findViewById(R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

        // Initialise this list somewhere with the content that should be displayed
        List<String> itemsToBeDisplayed;

        for (String subItem : itemsToBeDisplayed) {
            // Give along the name - you can use this to hand over an ID for example
            Bundle b = new Bundle();
            b.putString("TAB_ITEM_NAME", subItem);

            // Add a tab to the tabHost
            mTabHost.addTab(mTabHost.newTabSpec(subItem).setIndicator(subItem), YourContentFragment.class, b);
        }
        return rootView;
    }
}



/********************************************************
This class contains the actual content of a single tab  
**********************************************************/
public class YourContentFragment extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle extras = getArguments();
        if (extras != null) {
            if (extras.containsKey("TAB_ITEM_NAME")) {
                String subItem = extras.getString("TAB_ITEM_NAME");
                // Do something with that string
            }
        }
    }
}
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.support.v4.app.FragmentTabHost;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
公共类DetailFragment扩展了片段{
/******************************************************************************************************************
*片段管理器实例化片段的强制空构造函数(例如,在屏幕方向更改时)。
*****************************************************************************************************************/
公共详细信息片段(){
}
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
//R.layout.fragment_tabs_页面包含问题中指定的布局
视图根视图=充气机。充气(R.layout.fragment\u tabs\u页面,容器,false);
//初始化选项卡主机
FragmentTabHost mTabHost=(FragmentTabHost)rootView.findViewById(R.id.tabhost);
mTabHost.setup(getActivity(),getChildFragmentManager(),R.id.realtabcontent);
//用应该显示的内容在某个地方初始化此列表
列出要显示的项目;
for(字符串子项:ItemsToBedDisplayed){
//提供姓名-例如,您可以使用该名称来提交ID
Bundle b=新Bundle();
b、 putString(“选项卡项名称”,子项);
//将选项卡添加到tabHost
mTabHost.addTab(mTabHost.newTabSpec(子项).setIndicator(子项),YourContentFragment.class,b);
}
返回rootView;
}
}
/********************************************************
此类包含单个选项卡的实际内容
**********************************************************/
公共类YourContentFragment扩展了片段{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle extras=getArguments();
如果(附加值!=null){
if(附加容器(“选项卡项目名称”)){
String subItem=extras.getString(“TAB_ITEM_NAME”);
//用那根绳子做点什么
}
}
}
}

如果您需要将零碎的选项卡放在屏幕底部。。。 @休耕地--

使您的xml文件如下

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

       <!--   <RelativeLayout 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">  android:layout_alignParentTop="true"  -->

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


        <android.support.v4.app.FragmentTabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

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

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

    </LinearLayout>
LearnContainerFragment.java->它是xml文件容器\u fragment.xml

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container_framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </FrameLayout>
希望能有帮助。。。。。
干杯

我有同样的渲染问题和编译错误。我修复了这个问题,发现在创建Addtab时没有传递片段。您必须在mTabHost.addTab上传递至少一个片段。下面是工作代码

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(“书签”).setIndicator(“书签”);

这是错误日志还是控制台?如果是logcat,请post。这是一个错误日志:在eclipse中:(呈现期间引发的异常:在“窗口>显示视图>错误日志”中未记录标记null异常详细信息的已知选项卡)FragmentTabHost不会显示任何内容,因为将动态添加内容。所以没有他们的问题。当你在代码中添加标签并测试它时,应该可以工作。我打开了一个bug报告,请投票:好吧,一个普通的android.widget.TabHost就可以了,除了[android.app.TabActivity不推荐][TabActivity]支持使用FragmentTabHosts和Fragments。[活动]:[
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container_framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </FrameLayout>
public class BaseContainerFragment extends Fragment {

    public void replaceFragment(Fragment fragment, boolean addToBackStack) {
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        if (addToBackStack) {
            transaction.addToBackStack(null);
        }
        transaction.replace(R.id.container_framelayout, fragment);
        transaction.commit();
        getChildFragmentManager().executePendingTransactions();
    }

    public boolean popFragment() {
        Log.e("test", "pop fragment: " + getChildFragmentManager().getBackStackEntryCount());
        boolean isPop = false;
        if (getChildFragmentManager().getBackStackEntryCount() > 0) {
            isPop = true;
            getChildFragmentManager().popBackStack();
        }
        return isPop;
    }

}