ПОСТАНОВИЛИ.При отображении MapView внутри AlertDialog, диалоговые кнопки исчезли - PullRequest
0 голосов
/ 03 марта 2019

Я использую AlertDialog с несколькими пользовательскими макетами, и у меня возникла странная проблема с одним из них: я пытаюсь использовать вид карты Google в AlertDialog:

   // this common code used for all alert dialogs
   // I have different dialogIds so specific code is used where needed.

   AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
   final View view = viewInitializer.getView(dialogId, mActivity);
   builder.setMessage(message);
   builder.setCancelable(false);
   builder.setView(view)
   // Add action buttons
     .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
           // do something....
        }
   })
   .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
        }
   });

   Dialog dialog = builder.create();
   builder.show();

   .......
   // map view specific code
   final MapView mapView = view.findViewById(R.id.mapView);
   MapsInitializer.initialize(mActivity);

   mapView.onCreate(dialog.onSaveInstanceState());
   mapView.onResume();// needed to get the map to display immediately
   mapView.getMapAsync(new OnMapReadyCallback() {
      @Override
      public void onMapReady(GoogleMap googleMap) {
        final GoogleMap gmap = googleMap;
        gmap.setMinZoomPreference(12);
        LatLng ny = new LatLng(42.6021767,23.4674597);
        gmap.moveCamera(CameraUpdateFactory.newLatLng(ny));
      }
   });
   ...........

----------- шаблоны макетов: ------------ // один из диалогов, которые в порядке.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <NumberPicker
        android:id="@+id/seatsCountPicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="top"/>

</LinearLayout>

// the dialog with map view that are not ok.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:weightSum="5">

    <Spinner
        android:id="@+id/pointPicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/points"
        android:gravity="top"
        android:layout_weight="1"/>

    <Spinner
        android:id="@+id/pointPicker2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/points"
        android:gravity="top"
        android:layout_weight="1"/>

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="0pt"
        android:layout_weight="3"
        android:gravity="top"/>

</LinearLayout>

Другие диалоги в порядке Диалог с картой без кнопок.Я пытался установить маленький размер и различные веса вида карты, потому что я думал, что кнопки находятся за картой.но все еще нет кнопок.

Есть идеи?

[решено] Хм, странно.Если я удаляю «layout_weight» и использую только фиксированное значение для высоты, это нормально.Теперь мне осталось только найти способ справиться с экранами разных размеров.

Прикреплены скриншоты - все в порядке и диалог просмотра карты без кнопок. enter image description here

...