谷歌地图V2黑屏福尔摩斯和ListView [英] Google map v2 Black Screen with Sherlock and ListView

查看:171
本文介绍了谷歌地图V2黑屏福尔摩斯和ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似这里的OP(<一个href=\"http://stackoverflow.com/questions/13837697/viewpager-with-google-maps-api-v2-mysterious-black-view\">ViewPager与谷歌地图API第2版:神秘的黑色视图),黑色占据主导不只是一部分,但我所有的地图当与ListView控件中。我不相信这个主题在创造这个任何部分。当我试图将是OP的回答,我的整个片段转变成一个黑色的空白。

会有人介意看着我的片段,并帮我找出这个错误?

谢谢!

 &LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:地图=htt​​p://schemas.android.com/apk/res-auto
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直&GT;&LT; RelativeLayout的
    机器人:ID =@ + ID /图
    机器人:layout_width =match_parent
    机器人:layout_height =0dp
    机器人:layout_weight =1
    类=com.google.android.gms.maps.SupportMapFragment/&GT;&LT; ListView控件
    机器人:ID =@ + ID / map_frag_view
    机器人:layout_width =match_parent
    机器人:layout_height =0dp
    机器人:layout_weight =1/&GT;&LT; / LinearLayout中&GT;

我的片段是:

 公开查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
    //检查是否GooglePlayService开启 - &GT;应该把这个过一次先检查用户的力量有它
    布尔ifPlay = MainActivity.getInstance()checkIfGooglePlay()。    如果(ifPlay){
        如果(mapFragView!= NULL){
            ViewGroup中父=(ViewGroup中)mapFragView.getParent();
            如果(父!= NULL)
                parent.removeView(mapFragView);
        }
        尝试{
            mapFragView = inflater.inflate(R.layout.maptab,空,假);
        }赶上(InflateException E){
            / *地图已经存在,只是返回看法,因为它是* /
        }
    }    //从共享preferences创建MapFragment最近存储的信息
    。共享preferences tmpManager = MainActivity.getInstance()preFS;    字符串recWordAssoc = tmpManager.getString(wordAssociations,默认);
    //大厦名单
    的String [] =的thelist buildList(recWordAssoc);
    assocListView =(ListView控件)mapFragView.findViewById(R.id.map_frag_view);    如果(的thelist == NULL){
        的thelist =新的String [0];
    }    mapAdapter =新ArrayAdapter&LT;串GT;(getActivity(),android.R.layout.simple_list_item_1,的thelist);
    assocListView.setAdapter(mapAdapter);
    ((BaseAdapter)assocListView.getAdapter())notifyDataSetChanged();    如果(mapFragView!= NULL){
        setMapTransparent((ViewGroup中)mapFragView);
        返回mapFragView;
    }    ((ViewGroup中)assocListView.getParent())removeView(assocListView)。
    container.addView(assocListView);
    container.addView(mapFragView);    setMapTransparent(容器);
    返回容器中;
}


解决方案

尽量让thesurfaceview透明,而不是默认的黑色。 :
在SupportMapFragment类:

 公开查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
    查看查看= super.onCreateView(充气器,容器,savedInstanceState);
    setMapTransparent((ViewGroup中)查看);    返回视图。
}私人无效setMapTransparent(ViewGroup中组){
    INT childCount = group.getChildCount();
    的for(int i = 0; I&LT; childCount;我++){
        查看孩子= group.getChildAt(I)
        如果(孩子的instanceof的ViewGroup){
            setMapTransparent((ViewGroup中)的孩子);
        }否则如果(孩子的instanceof SurfaceView){
            child.setBackgroundColor(Color.TRANSPARENT);
        }
    }
}

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

解决方案

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

这篇关于谷歌地图V2黑屏福尔摩斯和ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆