これは画面上部に3つのタブ、つまり を表示するコードですが、画面にタブが表示されていないため、これがどうして起こっているのかわかりません答えを見つけ がここにXMLtabhostを使用してタブが表示されない
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="78dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
、ここでは、Javaコードが
final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setCurrentTab(1);
final TabHost.TabSpec tab1 = tabHost.newTabSpec("First Tab");
final TabHost.TabSpec tab2 = tabHost.newTabSpec("Second Tab");
final TabHost.TabSpec tab3 = tabHost.newTabSpec("Third Tab");
tab1.setIndicator("Upcoming").setContent(new Intent(this, Upcoming_matches.class));
tab2.setIndicator("Recent").setContent(new Intent(this, Recent_matches.class));
tab3.setIndicator("Fixture").setContent(new Intent(this, Fixtures.class));
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
tabHost.getTabWidget().getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams((int) Math.ceil((width/1)), 60));
tabHost.getTabWidget().getChildAt(1).setLayoutParams(new LinearLayout.LayoutParams((int) Math.ceil((width/3)), 60));
tabHost.getTabWidget().getChildAt(2).setLayoutParams(new LinearLayout.LayoutParams((int) Math.ceil((width/3)), 60));
です私を導く、ドン@の助けを借りて、それは基本的に間違っていレイアウトだった、でframeLayoutは、tabwidgetより以下でした正しいXMLは
0123です<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="78dp">
<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="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
であるあなたは、あなたのマニフェストでの活動を定義していますか? –
はい、その主要な活動の一部、他のコンポーネントは、これを除いては、あなたが完全なコードが必要な場合は、私はここに投稿することができますを働いています – nullByte
TabHostは長年にわたって廃止されました。代わりにTabLayoutを使用してください。 –