2017-02-15 1 views
2

내 동료 개발자 인사. 내가 TabHost를 사용하고, 2 탭 안에 내가 다른 TabHost를 사용하고자하는 안드로이드 프로젝트에 참여하고 , 지금까지 나는이 내 주요 TabHost의 XML이안드로이드 TabHost 내 tabHost의 탭

<TabHost 
    android:id="@+id/homeTabHost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"> 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

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

       <!--first tab content--> 
       <include layout="@layout/content_blood_glucose_diary_home" /> 

       <!--second tab content--> 
       <include layout="@layout/content_blood_glucose_diary_summary" /> 

       <!--3rd tab content--> 
       <include layout="@layout/content_blood_glucose_diary_activities" /> 

      </FrameLayout> 
     </LinearLayout> 

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

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

및 내 자바 코드 수행 한 이

private void loadTabs(int tabhost, String tab1, String tab2, String tab3){ 
    TabHost host = (TabHost)findViewById(tabhost); 
    host.setup(); 

    loadTab(host, R.id.homeTab1, tab1); //tab 1 

    loadTab(host, R.id.homeTab2, tab2); //tab 2 

    loadTab(host, R.id.homeTab3, tab3); //tab 3 
} 

private void loadTab(TabHost host, int tabid, String tab){ 
    TabHost.TabSpec spec = host.newTabSpec(tab); 
    spec.setContent(tabid); 
    spec.setIndicator(tab); 
    host.addTab(spec); 
} 

내가 사물이 작동하는이 시점에서 내에서 onCreate

loadTabs(R.id.homeTabHost, "Today", "Summary", "Activity"); 

부터 부르고있는 것입니다 greate하지만 (이 같은) 내 요약 XML의

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:weightSum="1"> 

    <TabHost 
     android:id="@+id/summaryTabHost" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.8"> 

     <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"> 

       <!--first tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab1" /> 
       </LinearLayout> 

       <!--second tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab2" /> 
       </LinearLayout> 

       <!--3rd tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab3" /> 
       </LinearLayout> 

       <!--4th tab content--> 
       <LinearLayout 
        android:id="@+id/summaryTab4" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="tab4" /> 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 

을 다른 tabhost를 추가하고 내 자바 파일에 때 난 내에서 OnCreate 함수에서

private void loadTabs(int tabhost, String tab1, String tab2, String tab3, String tab4){ 
    TabHost host = (TabHost)findViewById(tabhost); 
    host.setup(); 

    loadTab(host, R.id.summaryTab1, tab1); //tab 1 

    loadTab(host, R.id.summaryTab2, tab2); //tab 2 

    loadTab(host, R.id.summaryTab3, tab3); //tab 3 

    loadTab(host, R.id.summaryTab4, tab4); //tab 4 
} 

이 추가되는

loadTabs(R.id.summaryTabHost, "All", "Yearly", "Monthly", "Weekly"); 

입니다 이게 작동해야합니다 ... 그 첫 번째 탭 호스트와 동일하기 때문에 .. 첫 번째 탭 호스트 탭이 보이지 않는 ..

하지만 요약 XML 내부의 두 번째 탭 호스트에 댓글을 달았습니다. 정상적으로 보입니다.

나의 진단은 지금까지 아마도 제 2 TabHost에 앉아있는 것이 아닙니다.

어떤 아이디어가 잘못 될 수 있습니까 ??? 어떤 도움이 인정됩니다 !!

+0

에서 사용할 수 있도록하려는 경우 을 tablayout 사용할 수 있습니다 Depriected한다 하지만 만약 내가 화면 상단에 두 tabhosts 잘 작동 .. 그것도 잘 작동합니다 화면의 첫 번째 tabhost 상단과 화면의 내부 tabhost 하단을 만듭니다 .. 그것은 첫 번째 tabhost는 내가하려고하면 disapears 것 같습니다 내가 그랬던 것처럼해라. –

답변

0

TabHost는, 내가 화면의 하단에 tabhost를 생성 ... 당신은 탭 내부 탭이 쉽게이 예에서는 내부 조각

Androidhive tablayout tutorial

관련 문제