I am trying to add a Mapbox map inside of a dialog fragment.I have successfully added it i but when I run my application, the map isn't bound by the dialog as can be seen in the image below:
I have followed the getting started tutorial for adding the map into my dialog fragment (Maps Android SDK)
Is there a way I can prevent the map from sliding off of the dialog?
Here is how I start the dialog:
DialogFragment myDialog= MyDialog.newInstance();
myDialog.show(getActivity().getSupportFragmentManager(), "my_dialog");
My dialog xml is as follows:
<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>
Finally I initialize the map like so in my dialog:
@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;
}