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)));

		}

	}
}


참고 사이트



+ Recent posts