问题
I have used a Google Maps (V2) in a PopupWindow
and when I run the application, the map is not displayed. Even the area where it should be is fully transparent and I can see the activity below the PopupWindow
through it.
Any idea why this is?
Fragment inside popup_window.xml
<fragment
android:id="@+id/popup_alert_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/popup_alert_description"
android:layout_marginTop="10dp"
class="com.google.android.gms.maps.SupportMapFragment" />
And how I show it inside Popup.java
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.popup_alert_map);
locationMap = supportMapFragment.getMap();
locationMap.setMyLocationEnabled(true);
locationMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
I have another Activity
with a map it it and that displays nicely.
Any help greatly appreciated...
回答1:
If you are using the SupportMapFragment
then you should use the SupportFragmentManager
, like this:
locationMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.popup_alert_map)).getMap();
Try this, tell me what the result.
回答2:
It seems to be a bug, either in Android or in the MapFragment
/SupportMapFragment
. I tried the same thing (adding the Google Map fragment in a PopupWindow
) and on a Google Nexus 10 with Android 4.4, and the map appeared on the PopupWindow
just fine, but on an older device with Android 4.0.3 it showed the transparency problem.
Eventually what I did was just move it to another Activity
. I looked for as many ways as I could to fix it but it all seems like a dead end, especially given the fact that it works on the newest version of Android without any problems.
来源:https://stackoverflow.com/questions/15873511/transparent-google-map-on-popupwindow