我一直试图运行我创建的应用程序。运行后,它总是给我一个空白页而不是标签视图。下面是我的设计布局和片段中的代码。我在片段中使用tab host。
<RelativeLayout 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"
tools:context="com.example.redir.wealthtrack.UsageFragment">
<!-- TODO: Update blank fragment layout -->
<TabHost
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"></TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/Tab1"
layout="@layout/fragment_tag1"
android:layout_width="match_parent"
android:layout_height="68dp">
</include>
<include
android:id="@+id/Tab2"
layout="@layout/fragment_tag2"
android:layout_width="match_parent"
android:layout_height="match_parent">
</include>
<include
android:id="@+id/Tab3"
layout="@layout/fragment_tag3"
android:layout_width="match_parent"
android:layout_height="match_parent">
</include>
<include
android:id="@+id/Tab4"
layout="@layout/fragment_tag4"
android:layout_width="match_parent"
android:layout_height="match_parent">
</include>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
My fragments used for Tab view
package com.example.redir.wealthtrack;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TabHost;
import com.example.redir.wealthtrack.Tabs.Tag1;
/**
* A simple {@link Fragment} subclass.
*/
public class UsageFragment extends Fragment {
public UsageFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_usage, container, false);
TabHost tab = (TabHost) view.findViewById(R.id.tabHost);
tab.setup();
TabHost.TabSpec spec1 = tab.newTabSpec("Tab 1");
spec1.setIndicator("Tab 1");
spec1.setContent(R.id.Tab1);
tab.addTab(spec1);
TabHost.TabSpec spec2 = tab.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(R.id.Tab2);
tab.addTab(spec2);
TabHost.TabSpec spec3 = tab.newTabSpec("Tab 3");
spec3.setIndicator("Tab 3");
spec3.setContent(R.id.Tab3);
tab.addTab(spec3);
TabHost.TabSpec spec4 = tab.newTabSpec("Tab 4");
spec4.setIndicator("Tab 4");
spec4.setContent(R.id.Tab4);
tab.addTab(spec4);
return view;
}
}