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'? –