2013-06-10 3 views
1

탭 호스트를 사용하여 탭을 표시하지만 레이아웃에 드래그 앤 드롭하여 실행해도 탭이 보이지 않고 흰색 화면이 나타납니다. 첫 번째 탭보기의 선형 레이아웃탭 호스트가 탭을 표시하지 않습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

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

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <LinearLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/tab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

</LinearLayout> 

위에서 에뮬레이터 또는 전화 (Huawei Ascend P1)를 실행하면 탭이 표시되지 않습니다.

Screen shot

+1

일부 탭을 추가 했습니까? – Luksprog

+0

탭이 xml 레이아웃에 추가되었습니다. 프로그래밍을 통해 탭을 추가하셨습니까? – kaibuki

+0

예, 코드에 탭이 추가되었습니다. – Luksprog

답변

5

이 방금 TabHost는 XML 코드를 사용하여 만들 수 없기 때문에 간단하게 일어나고있다. 다음과 같이 TabHost에 TabSpec을 추가해야합니다.

TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); 

TabSpec tab1 = tabHost.newTabSpec("First Tab"); 
TabSpec tab2 = tabHost.newTabSpec("Second Tab"); 
TabSpec tab3 = tabHost.newTabSpec("Third Tab"); 

tab1.setIndicator("Tab1"); 
tab1.setContent(new Intent(this,TabActivity1.class)); 

tab2.setIndicator("Tab2"); 
tab2.setContent(new Intent(this,TabActivity2.class)); 

tab3.setIndicator("Tab3"); 
tab3.setContent(new Intent(this,TabActivity3.class)); 

tabHost.addTab(tab1); 
tabHost.addTab(tab2); 
tabHost.addTab(tab3); 
관련 문제