Black view when rendering Google Maps on fragment

蓝咒 提交于 2019-12-11 15:06:56

问题


I'm using sliding menu for Android here is the link, when I slide on rendered map fragment, the sliding menu goes blank.

Here is my map fragment code.

public class BasicMapActivity extends SherlockFragment {
    private MapView mMapView;
    private GoogleMap mMap;

    @Override
    public View onCreateView(LayoutInflater inflater, 
                             ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.basic_demo, null);
        // view.setBackgroundColor(0x00000000);
        mMapView = (MapView) view.findViewById(R.id.map);
        container.requestTransparentRegion(mMapView);
        mMapView.onCreate(savedInstanceState);
        return view;
    }
}

Here is my home activity where in i render map.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home_frame);
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.home_screen, new BasicMapActivity())
            .commit();


    getSlidingMenu().setSecondaryMenu(
            getLayoutInflater().inflate(R.layout.resq_events_frame, null));
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.resq_events_screen, new EventsFragment())
            .commit();

    // set the Behind View
    setBehindContentView(R.layout.activity_settings_frame);

    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.settings_screen, new SettingsFragment())
            .commit();

    // customize the SlidingMenu
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}

My XML file looks like this

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_screen"
    android:layout_width="match_parent"
    android:layout_height="match_parent">        
</FrameLayout>

How to overcome by this issue?

Here how the image looks.


回答1:


The issue is due to GoogleMap, you have to add this map:zOrderOnTop="true" to your XML map layout, like

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >

    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        xmlns:map="http://schemas.android.com/apk/res-auto"         
        android:id="@+id/map" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"
        map:zOrderOnTop="true" />

</LinearLayout>


来源:https://stackoverflow.com/questions/15049225/black-view-when-rendering-google-maps-on-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!