TabHost태그 사이에 LinearLayout으로 Tab버튼과 컨텐츠를 vertical정렬한다
TabWidget의 Height는 반드시 wrap_content로 지정되어야 한다
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9">
<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" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 컨텐츠 삽입 -->
</FrameLayout>
</LinearLayout>
</TabHost>
Activity에 다음 코드를 추가한다
이 때 setIndicator("")에 들어가는 텍스트가 탭의 제목이 된다
// TabHost 참조 후 TabHost.setup() 호출. 호출하지 않으면 TabWidget이 동작 안 함.
TabHost tabHost1 = (TabHost) findViewById(R.id.tabHost1);
tabHost1.setup();
// 첫 번째 Tab. (탭 표시 텍스트:"TAB 1"), (페이지 뷰:"content1")
TabHost.TabSpec ts1 = tabHost1.newTabSpec("Tab Spec 1");
ts1.setContent(R.id.content1) ;
ts1.setIndicator("TAB 1");
tabHost1.addTab(ts1);
// 두 번째 Tab. (탭 표시 텍스트:"TAB 2"), (페이지 뷰:"content2")
TabHost.TabSpec ts2 = tabHost1.newTabSpec("Tab Spec 2");
ts2.setContent(R.id.content2);
ts2.setIndicator("TAB 2");
tabHost1.addTab(ts2);
// 세 번째 Tab. (탭 표시 텍스트:"TAB 3"), (페이지 뷰:"content3")
TabHost.TabSpec ts3 = tabHost1.newTabSpec("Tab Spec 3");
ts3.setContent(R.id.content3);
ts3.setIndicator("TAB 3");
tabHost1.addTab(ts3);
'Android' 카테고리의 다른 글
[Android] '돌아가기' 버튼 구현 (0) | 2019.03.29 |
---|---|
[Android] Comparable 정렬 (0) | 2019.03.28 |
[Android] RecyclerView 예제 (0) | 2019.03.26 |
[Android] YouTube Api call Url (0) | 2019.03.22 |
YouTube Android Player API - Download (0) | 2019.03.20 |