谷歌地图v2黑屏与Sherlock和ListView

时间:2013-06-19 12:34:28

标签: android android-layout android-fragments google-play google-maps-api-2

与此处的OP(ViewPager with Google Maps API v2: mysterious black view)类似,当与ListView合并时,黑色不仅支持部分,而且支配我的所有Map。我不相信这个主题在创造这个主题中起任何作用。当我试图将OP的答案合并时,我的整个片段变成了一个黑色的空洞。

有人会介意看我的Fragment并帮我弄清楚这个错误吗?

谢谢!

<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>

我的片段是:

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

2 个答案:

答案 0 :(得分:1)

尝试使thesurfaceview透明而不是默认的黑色。 : 在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);
        }
    }
}

答案 1 :(得分:0)

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

https://github.com/NyxDigital/NiceSupportMapFragment