0

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;
}
4

2 回答 2

1

尝试使表面视图透明而不是默认的黑色。:在 SupportMapFragment 类中:

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);
        }
    }
}
于 2013-06-19T14:01:46.987 回答
0

您可以使用此替换类使表面视图变黑

https://github.com/NyxDigital/NiceSupportMapFragment

于 2013-06-25T14:08:45.943 回答