Professional Documents
Culture Documents
11 TabBar
11 TabBar
11 TabBar
Project : TabBarDemo
Clock
<TabHost
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
id : TabHost
width : parent
height : parent
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
id : tabs
height : TabBar
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
id : tabcontent
<LinearLayout
android:id = "@+id/tab1"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:orientation = "vertical"
android:gravity = "center" >
<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "This is Tab1"
android:textSize = "18pt" >
</TextView>
</LinearLayout>
id : tab1
orientation : vertical
gravity : center
<LinearLayout
android:id = "@+id/tab2"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:orientation = "vertical"
android:gravity = "center" >
<AnalogClock
android:layout_width = "wrap_content"
android:layout_height = "wrap_content" >
</AnalogClock>
</LinearLayout>
id : tab2
orientation : vertical
gravity : center
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class TabBarDemo extends Activity {
TabHost tabBar;
TabHost.TabSpec spec;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabBar = (TabHost)findViewById(R.id.tabHost);
tabBar.setup();
spec = tabBar.newTabSpec("Tab1");
spec.setContent(R.id.tab1);
spec.setIndicator("Tab1");
tabBar.addTab(spec);
spec = tabBar.newTabSpec("Tab2");
spec.setContent(R.id.tab2);
spec.setIndicator("Clock");
tabBar.addTab(spec);
}
}
TabHost tabBar;
TabHost.TabSpec spec;
tabBar = (TabHost)findViewById(R.id.tabHost);
tabBar.setup();
Tab
spec = tabBar.newTabSpec("Tab1");
2. Tab id Tab
LinearLayout id tab1
spec.setContent(R.id.tab1);
spec.setIndicator("Tab1");
tabBar.addTab(spec);
Tab 2 Tab 1
spec = tabBar.newTabSpec("Tab2");
spec.setContent(R.id.tab2);
spec.setIndicator("Clock");
tabBar.addTab(spec);
drbomkung@gmail.com