실행환경 | |
Notebook | SAMSUNG NT550p5c-s61r |
CPU | Intel Core i5-3210M 2.50GHz |
Memory | 8 GB |
OS | Window 7 ultimate 64bit |
Java | 1.7.0_51 |
| Android | SDK : 4.4.2 (KitKat) / 테스트기기 : Galaxy S3 4.3 (Jelly Bean) |
WebServer | Apache Tomcat 7.0 |
TabHost
여러 탭을 두고 각 탭을 클릭할 때마다 해당 화면이 나오도록 설정하는 뷰 컨테이너.
예제 결과
XML code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
</LinearLayout>
</TabHost>
</LinearLayout>
java code
package com.android_report;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabSpec tabSpecTab1 = tabHost.newTabSpec("TAB1").setIndicator("강아지");
tabSpecTab1.setContent(R.id.tab1);
tabHost.addTab(tabSpecTab1);
TabSpec tabSpecTab2 = tabHost.newTabSpec("TAB2").setIndicator("고양이");
tabSpecTab2.setContent(R.id.tab2);
tabHost.addTab(tabSpecTab2);
TabSpec tabSpecTab3 = tabHost.newTabSpec("TAB3").setIndicator("토끼");
tabSpecTab3.setContent(R.id.tab3);
tabHost.addTab(tabSpecTab3);
TabSpec tabSpecTab4 = tabHost.newTabSpec("TAB4").setIndicator("말");
tabSpecTab4.setContent(R.id.tab1);
tabHost.addTab(tabSpecTab4);
tabHost.setCurrentTab(0);
}
}
'대학 생활 > Android' 카테고리의 다른 글
| [Android] 이미지버튼(ImageButton) 배경 투명 (0) | 2014.05.30 |
|---|---|
| [Android] 이클립스 SDK 버튼이 보이지 않을 때 (0) | 2014.05.14 |
| [Android] Activity, Context 가져오기 (0) | 2014.05.05 |
| [Android] 파일출력시 openFileOutput 에러 (0) | 2014.05.01 |