android–MapFragment在旋转后变得无法响应

android–MapFragment在旋转后变得无法响应,第1张

概述我的问题很简单,我将4个FrameLayout添加到我的XML中,并在这些容器中按代码添加4个MapFragment.像这样:<LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:map="http://schemas.android.com/apkes-auto"android:id="@+id/map_container&

我的问题很简单,我将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>

在我的活动中

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);                fragmentTransaction.commit();mMap2Fragment = SupportMapFragment.newInstance(new GoogleMapOptions().zoomControlsEnabled(false).zoomGesturesEnabled(false).compassEnabled(false).rotateGesturesEnabled(false).scrollGesturesEnabled(false));    FragmentTransaction fragmentTransaction = getSupportFragmentManager()                        .beginTransaction();                fragmentTransaction.add(R.ID.map2_container, mMap2Fragment, MAP_FRAGMENT_TAG);                fragmentTransaction.commit();mMap3Fragment = SupportMapFragment.newInstance(new GoogleMapOptions().zoomControlsEnabled(false).zoomGesturesEnabled(false).compassEnabled(false).rotateGesturesEnabled(false).scrollGesturesEnabled(false));    FragmentTransaction fragmentTransaction = getSupportFragmentManager()                        .beginTransaction();                fragmentTransaction.add(R.ID.map3_container, mMap3Fragment, MAP_FRAGMENT_TAG);                fragmentTransaction.commit();mMap4Fragment = SupportMapFragment.newInstance(new GoogleMapOptions().zoomControlsEnabled(false).zoomGesturesEnabled(false).compassEnabled(false).rotateGesturesEnabled(false).scrollGesturesEnabled(false));    FragmentTransaction fragmentTransaction = getSupportFragmentManager()                        .beginTransaction();                fragmentTransaction.add(R.ID.map4_container, mMap4Fragment, MAP_FRAGMENT_TAG);                fragmentTransaction.commit();        setUpMAPIfNeeded();    }    @OverrIDe    protected voID onResume() {        super.onResume();        setUpMAPIfNeeded();    }    private voID setUpMAPIfNeeded() {        // Do a null check to confirm that we have not already instantiated the        // map.        if (mMap == null) {            mMap = mMap1Fragment.getMap();        }        if (mMapUp == null) {            mMapUp = mMap2Fragment.getMap();            mMapUp.setonMapClickListener(new OnMapClickListener() {                public voID onMapClick(LatLng arg0) {                    Cameraposition cp = mMapUp.getCameraposition();                    mMapUp.moveCamera(CameraUpdateFactory.newCameraposition(mMap.getCameraposition()));                    mMap.moveCamera(CameraUpdateFactory.newCameraposition(cp));                }            });        }        if (mMapMIDdle == null) {            mMapMIDdle = mMap3Fragment.getMap();            mMapMIDdle.setonMapClickListener(new OnMapClickListener() {                public voID onMapClick(LatLng arg0) {                    Cameraposition cp = mMapMIDdle.getCameraposition();                    mMapMIDdle.moveCamera(CameraUpdateFactory                            .newCameraposition(mMap.getCameraposition()));                    mMap.moveCamera(CameraUpdateFactory                            .newCameraposition(cp));                }            });        }        if (mMapLow == null) {            mMapLow = mMap4Fragment.getMap();            mMapLow.setonMapClickListener(new OnMapClickListener() {                public voID onMapClick(LatLng arg0) {                    Cameraposition cp = mMapLow.getCameraposition();                    mMapLow.moveCamera(CameraUpdateFactory                            .newCameraposition(mMap.getCameraposition()));                    mMap.moveCamera(CameraUpdateFactory                            .newCameraposition(cp));                }            });        }        initializeMapspositions();    }    private voID initializeMapspositions() {        if (mMap != null) {            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(                    47.224217, -1.631409), 16));        }        if (mMapUp != null) {            mMapUp.setonCamerachangelistener(new OnCamerachangelistener() {                public voID onCameraChange(Cameraposition arg0) {                    mMapUp.animateCamera(CameraUpdateFactory.newLatLngBounds(                            new LatLngBounds(new LatLng(-21.417276,55.039925),                                        new LatLng(-20.815174,56.008095)),                            10));                    mMapUp.setonCamerachangelistener(null);                }            });        }        if (mMapMIDdle != null) {            mMapMIDdle.setonCamerachangelistener(new OnCamerachangelistener() {                public voID onCameraChange(Cameraposition arg0) {                    mMapMIDdle.animateCamera(CameraUpdateFactory.newLatLngBounds(                            new LatLngBounds(new LatLng(14.337573,-61.441246),                                             new LatLng(14.947439,-60.603539)),                             10));                    mMapMIDdle.setonCamerachangelistener(null);                }            });        }        if (mMapLow != null) {            mMapLow.setonCamerachangelistener(new OnCamerachangelistener() {                public voID onCameraChange(Cameraposition arg0) {                    mMapLow.animateCamera(CameraUpdateFactory.newLatLngBounds(                            new LatLngBounds(new LatLng(17.596903,-78.448288),                                             new LatLng(18.643643,-76.207077)),                             10));                    mMapLow.setonCamerachangelistener(null);                }            });        }    }}

问题是:当我旋转设备时,MapFragments不再重新触摸事件……

有没有人有同样的问题并解决它?

解决方法:

我遇到了同样的问题,经过多次故障排除后发现容器中有多个地图碎片.

所以,我通过使用解决了这个问题

FragmentTransaction.replace

代替

.add
总结

以上是内存溢出为你收集整理的android – MapFragment在旋转后变得无法响应全部内容,希望文章能够帮你解决android – MapFragment在旋转后变得无法响应所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106381.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存