#2
wkz20122013-04-24 11:04
|
程序代码:
实现部分TabHostActivity.java
package com.map;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
public class TabHostActivity extends TabActivity {
private TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhost);
tabHost = this.getTabHost();
initTabs();
}
private void initTabs() {
tabHost.setup(this.getLocalActivityManager());
// 添加线路规划的tab
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("线路规划",getResources().getDrawable(R.drawable.tabpic1))
.setContent(new Intent(this, FirstActivity.class)));
// 添加城市名片的tab
tabHost.addTab(tabHost.newTabSpec("tab5")
.setIndicator("城市名片",getResources().getDrawable(R.drawable.tabpic5))
.setContent(new Intent(this, FifthActivity.class)));
}
}
xml布局文件tabhost.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas. android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</LinearLayout>
package com.map;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
public class TabHostActivity extends TabActivity {
private TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhost);
tabHost = this.getTabHost();
initTabs();
}
private void initTabs() {
tabHost.setup(this.getLocalActivityManager());
// 添加线路规划的tab
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("线路规划",getResources().getDrawable(R.drawable.tabpic1))
.setContent(new Intent(this, FirstActivity.class)));
// 添加城市名片的tab
tabHost.addTab(tabHost.newTabSpec("tab5")
.setIndicator("城市名片",getResources().getDrawable(R.drawable.tabpic5))
.setContent(new Intent(this, FifthActivity.class)));
}
}
xml布局文件tabhost.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas. android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</LinearLayout>