2016-06-05 2 views
0

3 개의 탭이있는 활동을 구현하려고합니다. 이 목적으로 FragmentTabHost를 사용하기로 결정했습니다. 나는 다음과 같은 레이아웃 파일 일부 코드 예제를 발견했습니다FragmentTabHost에서 TabWidget을 명시 적으로 정의해야합니까?

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

    <android.support.v4.app.FragmentTabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"/> 
    </android.support.v4.app.FragmentTabHost> 

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

를하지만 앞의 코드 샘플 TabWidget없이 동일한 방식으로 작동하는지 이해했을 때 나는 깜짝 놀랐다 : 의도 한대로 난 그냥 내 탭이 표시

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

    <android.support.v4.app.FragmentTabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </android.support.v4.app.FragmentTabHost> 

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

</LinearLayout> 

을 . FragmentTabHost의 소스 코드에 따르면, 뷰의 계층 구조에서 찾을 수없는 경우 TabWidget을 단독으로 만듭니다. 그래서 내 레이아웃 파일에 명시 적으로 TabWidget을 선언해야하는지 궁금합니다.

답변

1

글쎄, 당신이 묘사하는 행동은 문서화되지 않았기 때문에 언젠가이 기능을 떨어 뜨리면 약간의 회귀 위험이 있습니다. 물론 TabWidget 아이를 갖는 것은 문서화되지 않았기 때문에 FragmentTabHost에 대한 문서는 엿 같아요.

XML 속성을 통해 TabWidget 렌더링의 일부 측면에 대한 선언적 컨트롤을 원한다면 TabWidget을 레이아웃에 넣을 수도 있습니다.

그래도 생성 된 기본값 TabWidget이 유용하면 사용하실 수 있습니다.

+0

신속하고 완전한 응답을 보내 주셔서 감사합니다. 네가 옳아. TabWidget 및 FragmentTabHost 설명서에는 몇 가지 세부 사항이 없습니다. –

관련 문제