Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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 选项卡位于片段中,但布局未显示_Android_Android Studio_Android Fragments_Android Tabs - Fatal编程技术网

Android 选项卡位于片段中,但布局未显示

Android 选项卡位于片段中,但布局未显示,android,android-studio,android-fragments,android-tabs,Android,Android Studio,Android Fragments,Android Tabs,从星期五开始,我尝试在一个类(FragmentCV.class)中创建3个标签,扩展fragment 现在,我想我知道了,但它仍然不能正常工作 应用程序没有崩溃,我也没有收到任何错误/警告消息 当我试图打开FragmentCV.java时,它应该会显示这3个选项卡的布局 但不知怎么的,我什么也没看到。它是空的,但在XML文件中我可以看到这些选项卡 FragmentCV.java import android.os.Bundle; import android.support.v4.app.Fra

从星期五开始,我尝试在一个类(FragmentCV.class)中创建3个标签,扩展fragment

现在,我想我知道了,但它仍然不能正常工作

应用程序没有崩溃,我也没有收到任何错误/警告消息

当我试图打开FragmentCV.java时,它应该会显示这3个选项卡的布局

但不知怎么的,我什么也没看到。它是空的,但在XML文件中我可以看到这些选项卡

FragmentCV.java

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 FragmentCV extends Fragment {

    private FragmentTabHost mTabHost;


    public FragmentCV() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        //view = inflater.inflate(R.layout.fragment_cv, container, false);

        mTabHost = new FragmentTabHost(getActivity());
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1);

        mTabHost.addTab(
                mTabHost.newTabSpec("personal Profile").setIndicator("Personal Profile", null),
                FragmentCVpage1.class, null);
        mTabHost.addTab(
                mTabHost.newTabSpec("education").setIndicator("Education", null),
                Fragment_CVpage2.class, null);
        mTabHost.addTab(
                mTabHost.newTabSpec("bla").setIndicator("Bla", null),
                FragmentCVpage3.class, null);

        return mTabHost;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mTabHost = null;
    }
}
fragment_cv.XML

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

    <TabHost
        android:layout_marginTop="50dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabHost"
        android:layout_gravity="center_horizontal">

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

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:orientation="horizontal">
            </TabWidget>
            <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="horizontal">
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="horizontal">
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="horizontal">
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>

编辑:也许我应该说,我使用的是“导航抽屉布局”类

使用“导航抽屉”,我调用“FragmentCV.java片段”

所以当我启动应用程序时:

  • 将打开MainActivity.java(导航抽屉布局)。它包含一个“抽屉”、“工具栏”和一个名为“content_main.xml”的片段
  • 我打开抽屉,按下一个按钮来调用“FragmentCV.java”
  • 现在我应该看到带有3个选项卡的“fragment\u cv.xml”,但我仍然看到了“content\u main.xml”布局。因此,“fragment\u cv.xml”似乎没有出现