Android 选项卡位于片段中,但布局未显示
从星期五开始,我尝试在一个类(FragmentCV.class)中创建3个标签,扩展fragment 现在,我想我知道了,但它仍然不能正常工作 应用程序没有崩溃,我也没有收到任何错误/警告消息 当我试图打开FragmentCV.java时,它应该会显示这3个选项卡的布局 但不知怎么的,我什么也没看到。它是空的,但在XML文件中我可以看到这些选项卡 FragmentCV.javaAndroid 选项卡位于片段中,但布局未显示,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
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片段”
所以当我启动应用程序时: