Google map v2 Black Screen with Sherlock and ListView

做~自己de王妃 提交于 2019-12-11 21:07:35

问题


Similar to the OP here (ViewPager with Google Maps API v2: mysterious black view), black dominates not just part but all of my Map when incorporated with the ListView. I do not believe the theme plays any part in creating this. When I attempted to incorporate that OP's answer, my entire fragment transformed into a black void.

Would someone mind looking at my Fragment and help me figure out this error?

Thanks!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    class="com.google.android.gms.maps.SupportMapFragment" />

<ListView
    android:id="@+id/map_frag_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

</LinearLayout>

My Fragment is:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    //Checks if GooglePlayService is On--> Should take this out once first check forces user to have it 
    boolean ifPlay = MainActivity.getInstance().checkIfGooglePlay();

    if(ifPlay) {
        if (mapFragView != null) {
            ViewGroup parent = (ViewGroup) mapFragView.getParent();
            if (parent != null)
                parent.removeView(mapFragView);
        }
        try {
            mapFragView = inflater.inflate(R.layout.maptab, null, false);
        } catch (InflateException e) {
            /* map is already there, just return view as it is */
        }
    }

    //Creating MapFragment from SharedPreferences recently stored information 
    SharedPreferences tmpManager = MainActivity.getInstance().prefs;

    String recWordAssoc = tmpManager.getString("wordAssociations", "default");


    //Building list 
    String[] theList = buildList(recWordAssoc);
    assocListView = (ListView) mapFragView.findViewById(R.id.map_frag_view);

    if(theList==null) {
        theList = new String[0];
    }

    mapAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,  theList);
    assocListView.setAdapter(mapAdapter);
    ((BaseAdapter) assocListView.getAdapter()).notifyDataSetChanged();



    if(mapFragView != null) { 
        setMapTransparent((ViewGroup)mapFragView);
        return mapFragView;
    }

    ((ViewGroup) assocListView.getParent()).removeView(assocListView);


    container.addView(assocListView);
    container.addView(mapFragView);

    setMapTransparent(container);
    return container;
}

回答1:


Try to make thesurfaceview transparent instead of the default black. : In the SupportMapFragment class :

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    setMapTransparent((ViewGroup) view);

    return view;
}

private void setMapTransparent(ViewGroup group) {
    int childCount = group.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = group.getChildAt(i);
        if (child instanceof ViewGroup) {
            setMapTransparent((ViewGroup) child);
        } else if (child instanceof SurfaceView) {
            child.setBackgroundColor(Color.TRANSPARENT);
        }
    }
}



回答2:


You can use this replacement class to make the surface view black

https://github.com/NyxDigital/NiceSupportMapFragment



来源:https://stackoverflow.com/questions/17191335/google-map-v2-black-screen-with-sherlock-and-listview

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