main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="@+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" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
</LinearLayout>
tabhost의 id가 @android:id/tabhost가 아닌 @+id/tabhost 이다.
위 tab은 FrameLayout 속성에 layout_weight="1" 때문에 하단에 위치하게 된다.
MainActivity.java
public class MainActivity extends ActivityGroup {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
createTab();
}
private void createTab() {
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup(getLocalActivityManager());
tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("TAB1")
.setContent(new Intent(this, Tab1Activity.class)));
tabHost.addTab(tabHost.newTabSpec("TAB2").setIndicator("TAB2")
.setContent(new Intent(this, Tab2Activity.class)));
}
}
}참고 사이트
'대학 생활 > Android' 카테고리의 다른 글
| [Android] 메일 보내기 (0) | 2014.06.25 |
|---|---|
| [Android] ListView 스크롤바 감추기, 조절하기(scrollbar, fast scrollbar) (0) | 2014.06.15 |
| [Android] version code, name 가져오기 (0) | 2014.06.10 |
| [Android]setText()에 개행(엔터), 태그 넣기 (0) | 2014.06.10 |