public class TabMapsExample extends TabActivity { TabHost mTabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Context ctx = this.getApplicationContext(); //tab 1 mTabHost = getTabHost(); TabSpec tabSpec1 = mTabHost.newTabSpec("tab_test1"); tabSpec1.setIndicator("Map1"); Intent i1 = new Intent(ctx, MapTabView.class); tabSpec1.setContent(i1); mTabHost.addTab(tabSpec1); //tab2 mTabHost = getTabHost(); TabSpec tabSpec2 = mTabHost.newTabSpec("tab_test1"); tabSpec2.setIndicator("Map2"); Intent i2 = new Intent(ctx, MapTabView.class); tabSpec2.setContent(i2); mTabHost.addTab(tabSpec2); //tab 3 mTabHost = getTabHost(); TabSpec tabSpec3 = mTabHost.newTabSpec("tab_test1"); tabSpec3.setIndicator("Map"); Intent i3 = new Intent(ctx, MapTabView.class); tabSpec3.setContent(i3); mTabHost.addTab(tabSpec3); } }
这是地图和tabHost的使用
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/maptablayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="#000000" android:orientation="vertical"> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="50px" android:id="@+id/textview" /> <com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="" /> </LinearLayout> </RelativeLayout>
上面的红线是必须的 apiKey是每个人都有一个特定的值
mapView.getController().zoomIn();
mapView.getController().zoomOut();
mapView.getController().setZoom(...);
Intent intent = new Intent(this, MyMapActivity.class); //this is just one way of specifying it intent.putExtra(MyMapActivity.ZOOM_LEVEL_CONSTANT, 10); startActivity(intent);
在MyMapActivity onCreate(...)
Bundle retrievedData = this.getIntent().getExtras(); if (retrievedData != null) { int zoomLevel = retrievedData.getInt(ZOOM_LEVEL_CONSTANT); mapView.getController.setZoom(zoomLevel); }
有时候你可能用到
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(10);
那么如何在mapActivity加入菜单呢
其实很简单 你只要继承activity就可以了
其他的不变和activity一样
http://developer.android.com/intl/fr/guide/topics/ui/menus.html