我的问题很简单,我将4个FrameLayout添加到我的XML中,并在这些容器中按代码添加4个MapFragment.
像这样 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/map1_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5""/>
<FrameLayout
android:id="@+id/map2_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal">
<fragment
android:id="@+id/map3_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"/>
<fragment
android:id="@+id/map4_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5""/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在我的活动中
public class MultiGoogleMapActivity extends FragmentActivity {
private GoogleMap mMap;
private GoogleMap mMapUp;
private GoogleMap mMapMiddle;
private GoogleMap mMapLow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multi_google_map);
mMap1Fragment = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.add(R.id.map1_container, mMap1Fragment, MAP_FRAGMENT_TAG); …Run Code Online (Sandbox Code Playgroud)