Android Map goes black when slide menu activates -
in app have set few tabs using fragmentactivity , button beside tabs activates slide menu. @ moment have 2 fragments displayed tab 1 , 2. fragment tab 1 contains v2 google map , second blank screen.

however when activate slide menu different behavior, have used slide menu lib several projects without problems. when activate slide menu while fragment 2 displayed works fine when fragment 1 (map view) displayed, activating slide menu causes map go black , displays map again when slide menu closed.

here code setting tab
xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <tabhost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparentleft="true" android:layout_alignparenttop="true" > <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:id="@+id/linearlayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:orientation="vertical" > <button android:id="@+id/button1" style="?android:attr/buttonstylesmall" android:layout_width="fill_parent" android:layout_height="55dp" android:text="button" /> </linearlayout> <linearlayout android:id="@+id/linearlayout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:layout_torightof="@+id/linearlayout1" android:orientation="vertical" > <tabwidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" > </tabwidget> </linearlayout> <framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_below="@+id/linearlayout1" > <framelayout android:id="@+id/tab_1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <framelayout android:id="@+id/tab_2" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <framelayout android:id="@+id/tab_3" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <framelayout android:id="@+id/tab_4" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </framelayout> </relativelayout> </tabhost> java
public class tabsfragment extends fragment implements ontabchangelistener { private static final string tag = "fragmenttabs"; public static final string tab_map = "map"; public static final string tab_venues = "venus"; public static final string tab_genre = "gap"; public static final string tab_tickets = "titus"; private view mroot; private tabhost mtabhost; int mcurrenttab; button slide_btn; @override public void onattach(activity activity) { super.onattach(activity); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { mroot = inflater.inflate(r.layout.tabs_fragment, null); mtabhost = (tabhost) mroot.findviewbyid(android.r.id.tabhost); setuptabs(); return mroot; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); setretaininstance(true); mtabhost.setontabchangedlistener(this); mtabhost.setcurrenttab(0); // manually start loading stuff in first tab updatetab(tab_map, r.id.tab_1); } private void setuptabs() { mtabhost.setup(); // important! mtabhost.addtab(newtab(tab_map, r.id.tab_1, r.drawable.tab_home)); mtabhost.addtab(newtab(tab_venus, r.id.tab_2, r.drawable.tab_home)); mtabhost.addtab(newtab(tab_gap, r.id.tab_3, r.drawable.tab_home)); mtabhost.addtab(newtab(tab_titus, r.id.tab_4, r.drawable.tab_home)); } private tabspec newtab(string tag, int tabcontentid, int drawableid) { log.d(tag, "buildtab(): tag=" + tag); view indicator = layoutinflater.from(getactivity()).inflate( r.layout.tabindicator, (viewgroup) mroot.findviewbyid(android.r.id.tabs), false); imageview icon = (imageview) indicator.findviewbyid(r.id.icon); icon.setimageresource(drawableid); tabspec tabspec = mtabhost.newtabspec(tag); tabspec.setindicator(indicator); tabspec.setcontent(tabcontentid); return tabspec; } @override public void ontabchanged(string tabid) { log.d(tag, "ontabchanged(): tabid=" + tabid); if (tab_map.equals(tabid)) { updatetab(tabid, r.id.tab_1); mcurrenttab = 0; return; } if (tab_venus.equals(tabid)) { updatetab(tabid, r.id.tab_2); mcurrenttab = 1; return; } if (tab_gap.equals(tabid)) { updatetab(tabid, r.id.tab_3); mcurrenttab = 2; return; } if (tab_titus.equals(tabid)) { updatetab(tabid, r.id.tab_4); mcurrenttab = 3; return; } } public void updatetab(string tabid, int placeholder) { if (tabid.equals("map")) { fragmentmanager fm = getfragmentmanager(); if (fm.findfragmentbytag(tabid) == null) { getfragmentmanager().begintransaction().add(placeholder, new myfrag(), "map").commit(); } } else if (tabid.equals("venus")) { fragmentmanager fm = getfragmentmanager(); if (fm.findfragmentbytag(tabid) == null) { getfragmentmanager().begintransaction().add(placeholder, new green(), "venus").commit(); } } else if (tabid.equals("gap")) { } else if (tabid.equals("titus")) { } } public void slidemenu(){ if(isadded()){ int width = (int) typedvalue.applydimension( typedvalue.complex_unit_dip, 200, getresources() .getdisplaymetrics()); slideoutactivity.prepare(getactivity(), r.id.inner_content, width); intent = new intent(); i.setclass(getactivity(), slidemenuactivity.class); i.setflags(intent.flag_activity_new_task); startactivity(i); getactivity().overridependingtransition(0, 0); } } }
then render in fragmentactivity own layout containing fragment.
here code i've used map
xml
<relativelayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".main" > <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/relativelayout1" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:focusable="true" android:focusableintouchmode="true" android:orientation="vertical" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.supportmapfragment" /> </linearlayout> <relativelayout android:id="@+id/relativelayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" > <imagebutton android:id="@+id/button3" style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_centervertical="true" android:src="@drawable/search_selected" /> <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_torightof="@+id/button3" android:ems="10" android:inputtype="text" > </edittext> </relativelayout> java
public class myfrag extends fragment { googlemap map; private static view view; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { if (view != null) { viewgroup parent = (viewgroup) view.getparent(); if (parent != null) parent.removeview(view); } try { view = inflater.inflate(r.layout.main, container, false); new loadmap().execute(); } catch (inflateexception e) { /* map there, return view */ } return view; } public class loadmap extends asynctask<string, integer, location> { locationmanager lm; latlng p = new latlng(51.50703296721856, -0.11260986328125); @override protected location doinbackground(string... params) { map = ((supportmapfragment) getactivity() .getsupportfragmentmanager().findfragmentbyid(r.id.map)) .getmap(); locationmanager locationmanager = (locationmanager) getactivity() .getsystemservice(context.location_service); criteria criteria = new criteria(); string provider = locationmanager.getbestprovider(criteria, true); location location = locationmanager.getlastknownlocation(provider); p = new latlng(location.getlatitude(), location.getlongitude()); return location; } protected void onpostexecute(location location) { try { if (location != null) { map.setmylocationenabled(true); map.movecamera(cameraupdatefactory.newlatlng(p)); map.movecamera(cameraupdatefactory.zoomto(15)); map.setoncamerachangelistener(null); } else { toast.maketext(getactivity(), "you got nada", toast.length_long).show(); } } catch (exception e) { e.printstacktrace(); } } } }
this known issue.
you may find workaround case here:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4639
or here:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4659
Comments
Post a Comment