我遇到了同样的问题,并通过在 Activity 上添加 TabHost 来解决它。您可以将 MapActivity 设置为选项卡内容并隐藏它的按钮。
示例代码:
地图.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</LinearLayout>
主.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/menu_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="menu" />
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</TabHost>
</LinearLayout>
MyMapActivity.java:
public class MyMapActivity extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
我的活动.java:
public class MyActivity extends TabActivity
{
private LayoutInflater inflater;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
inflater = LayoutInflater.from(context);
// Inflate menu here
// Get the TabHost
TabHost tabHost = getTabHost();
// Add the button and content
TabHost.TabSpec spec = tabHost.newTabSpec("myMapTab")
.setIndicator("Map")
.setContent(new Intent(this, MyMapActivity.class));
tabHost.addTab(spec);
// Hide the button
tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE);
MapView mapView = (MapView) tabHost.getTabContentView().getChildAt(0).findViewById(R.id.mapview)
}
}
我希望这能解决你的问题。