이 코드는 화면 상단에 세 개의 탭을 표시합니다. 그러나 화면에 탭이 표시되지 않습니다.이 상황이 발생하는 이유는 무엇인지 알 수 없습니다. 날 여기 안내 여기에 XML탭 호스트를 사용하여 탭이 나타나지 않습니다.
<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>
이고 것은 @의 도움으로, 자바 코드 답을 찾을 수
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>
당신이 매니페스트의 활동을 정의한 XML? –
그렇습니다. 주요 활동의 일부입니다. 다른 구성 요소가 정상적으로 작동하고 있습니다. 단, 전체 코드를 원할 경우 여기에 게시 할 수 있습니다. – nullByte
수십 년간 TabHost가 더 이상 사용되지 않습니다. 대신에 TabLayout을 사용하십시오. –