我正在尝试在对话框片段中添加Mapbox映射。我已经成功添加了它,但是当我运行我的应用程序时,该映射不受对话框的约束,如下图所示:>
我已经按照入门教程将地图添加到对话框片段(Maps Android SDK)
有没有办法防止地图从对话框中滑出?
这是我启动对话框的方式:
DialogFragment myDialog= MyDialog.newInstance();
myDialog.show(getActivity().getSupportFragmentManager(), "my_dialog");
我的对话框xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:mapbox="http://schemas.android.com/tools"
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundGrey">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<RelativeLayout
android:id="@+id/mapContainer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="center_vertical"
android:layout_marginTop="8dp"
android:orientation="vertical">
<!-- Mapbox map -->
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
...
</ScrollView>
最后,我在对话框中像这样初始化地图:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
_mapView = (MapView) convertView.findViewById(R.id.mapView);
_mapView.onCreate(savedInstanceState);
_mapView.onResume();
_mapView.getMapAsync(this);
...
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
this._mapboxMap = mapboxMap;
}