制作如下布局:
<FrameLayout
android:id="@+id/layout_mapContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="0"
android:background="@android:color/transparent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent" />
</FrameLayout>
在“活动”声明中:
FrameLayout mapLayout = (FrameLayout)findViewById(R.id.layout_mapContainer);
初始化映射,如下所示:
private void initialiseMap() {
FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
SupportMapFragment mFRaFragment = new MapFragmentActivity();
mTransaction.add(mapLayout.getId(), mFRaFragment);
mTransaction.commit();
try {
MapsInitializer.initialize(context);
} catch (Exception e) {
e.printStackTrace();
}
}
这里 MapFragmentActivity is class extend supportMapFragment