0
我想在片段中显示MapView。地图显示为我所期望的,但它似乎只是作为图片显示。我无法拖动移动相机或传播/捏缩放。我也尝试在我的片段中使用SupportMapFragment,但得到了相同的结果。Android MapView在初始化后的片段冻结(不可点击或拖动)
我在我的Activity中有一个NavigationView。我不认为NavigationView和MapView触摸事件存在冲突。
以前有人遇到过这个吗?
片段
public class CustomizedMapFragment extends Fragment implements OnMapReadyCallback{
MapView mapView;
GoogleMap googleMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
mapView = (MapView) rootView.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
return rootView;
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
this.googleMap.getUiSettings().setZoomControlsEnabled(true);
this.googleMap.getUiSettings().setZoomGesturesEnabled(true);
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:layout_margin="16dp"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
看看这里的答案,它可能会有所帮助:http://stackoverflow.com/questions/5758081/mapview-works-incorrect –
@DanielNugent我试图设置clickable为true,但它不起作用 – DemonPilot
Did你实现了'OnMapClickListener'? –