2016-11-26 1 views
0

나는 안드로이드를 처음 접했다. includes가 포함 된 탭 호스트를 갖고 싶지만 탭이 표시되지 않습니다. 이 입력란에는 텍스트 상자 및 버튼과 같은 간단한 입력 로직이 포함됩니다. 모든 코드는 db 항목 등을 저장하는 것과 같은 주요 활동 내에 있습니다.TabHost 및 포함

다음은 코드입니다.

<TabHost 
 
     xmlns:android="http://schemas.android.com/apk/res/android" 
 
     android:id="@+id/tabHost" 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="match_parent"> 
 
     <LinearLayout 
 
      android:id="@+id/line" 
 
      android:layout_width="fill_parent" 
 
      android:layout_height="match_parent" 
 
      android:orientation="vertical"> 
 
      <TabWidget 
 
       android:id="@android:id/tabs" 
 
       android:layout_width="fill_parent" 
 
       android:layout_height="wrap_content" 
 
       android:layout_weight="0"></TabWidget> 
 
      <FrameLayout 
 
       android:id="@android:id/tabcontent" 
 
       android:layout_width="fill_parent" 
 
       android:layout_height="0dip" 
 
       android:layout_weight="1"> 
 
       <include android:id="@+id/layout1" 
 
        layout="@layout/layout_add_details" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="match_parent"></include> 
 
       <include android:id="@+id/layout2" 
 
        layout="@layout/layout_add_number" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="match_parent"></include> 
 
      </FrameLayout> 
 
     </LinearLayout> 
 
    </TabHost>

는 여기에 어떻게 설정 tabhost.

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     TabHost tab = (TabHost) findViewById(R.id.tabHost); 
     tab.setup(); 

     TabHost.TabSpec spec1 = tab.newTabSpec("TAB 1"); 
     spec1.setIndicator("TAB 1"); 
     spec1.setContent(R.id.layout1); 
     tab.addTab(spec1); 

     TabHost.TabSpec spec2 = tab.newTabSpec("TAB 2"); 
     spec2.setIndicator("TAB 2"); 
     spec2.setContent(R.id.layout2); 
     tab.addTab(spec2); 
} 

미리 감사드립니다.

답변

0

내가 어떻게 해결 했는가? 나는 세 개의 탭이있는 Tabhost를 가지고있다. 두 번째에는 Google의지도 조각이 있고 다른 두 곳에는 간단한 텍스트 상자가 있습니다. 만 세 번째 탭그래서이 메인 레이아웃이

<TabHost 
     android:id="@+id/tab_host_main" 
     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="40dp" /> 

      <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" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="tab one"/> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/map_tab" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <fragment 
         android:id="@+id/map" 
         android:name="com.google.android.gms.maps.SupportMapFragment" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         tools:context=".MapsActivity" /> 
       </LinearLayout> 

       <FrameLayout 
        android:id="@+id/tab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <include 
         layout="@layout/tab_three_content" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" /> 


       </FrameLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

같은 모습입니다 그리고 이것이 내가 별도로 작성 이전에 삽입 된 탭 세 가지 레이아웃입니다

설정을 포함하여 추가한다 포함을 사용하여 레이아웃.

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

</LinearLayout>