java - MapView is only refreshing when it's touched -
i have mapview in fragment , want show user's current location. problem it's refreshed (in layers, first terrain, name of streets...) when mapview touched. shows front camera preview also. here's code. fragment layout
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <relativelayout android:id="@+id/otherrelative" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:gravity="center" > <textview android:id="@+id/textview2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="16dp" android:gravity="center" android:text="some text" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/textview2" android:gravity="center" android:text="some text" android:textappearance="?android:attr/textappearancemedium" /> </relativelayout> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_below="@+id/otherrelative" > <framelayout android:id="@+id/campreview" android:layout_width="163dp" android:layout_height="211dp" > </framelayout> <com.google.android.gms.maps.mapview xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.08" app:camerazoom="15" map:maptype="normal" > </com.google.android.gms.maps.mapview> </linearlayout> </relativelayout>
and fragment code
public class marcacionfragment extends fragment { // graphics private camera mcam; private mirrorview mcampreview; private framelayout mpreviewlayout; private mapview viewmap; private googlemap map; // size of camera preview private int size = 500; private gpstracker gps; private int mcameraid = 0; private cameraupdate cameraupdate; public marcacionfragment() { } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // retain fragment setretaininstance(true); } public void onresume() { super.onresume(); if (mcam == null && mpreviewlayout != null) { mpreviewlayout.removeallviews(); startcamerainlayout(mpreviewlayout, mcameraid, getview()); } } @override public void onpause() { if (mcam != null) { mcam.release(); mcam = null; } super.onpause(); } public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.marcacion_layout, container, false); mcameraid = findfirstfrontfacingcamera(); mpreviewlayout = (framelayout) rootview.findviewbyid(r.id.campreview); viewmap = (mapview) rootview.findviewbyid(r.id.map); viewmap.oncreate(savedinstancestate); map = viewmap.getmap(); map.getuisettings().setmylocationbuttonenabled(false); map.getuisettings().setallgesturesenabled(true); map.setmylocationenabled(true); mpreviewlayout.removeallviews(); startcamerainlayout(mpreviewlayout, mcameraid, rootview); mapsinitializer.initialize(this.getactivity()); // start gps service gps = new gpstracker(rootview.getcontext()); if (gps.cangetlocation()) { latlng latlng = new latlng(gps.getlatitude(), gps.getlongitude()); cameraupdate = cameraupdatefactory.newlatlngzoom(latlng, 15); map.getuisettings().setmaptoolbarenabled(false); map.getuisettings().setzoomcontrolsenabled(true); map.animatecamera(cameraupdate); map.addmarker(new markeroptions().position(latlng).draggable(true)); viewmap.setclickable(false); } else { gps.showsettingsalert(); } viewmap.invalidate(); return rootview; } @suppresslint("newapi") private int findfirstfrontfacingcamera() { int foundid = -1; int numcams = camera.getnumberofcameras(); (int camid = 0; camid < numcams; camid++) { camerainfo info = new camerainfo(); camera.getcamerainfo(camid, info); if (info.facing == camerainfo.camera_facing_front) { foundid = camid; break; } } return foundid; } private void startcamerainlayout(framelayout layout, int cameraid, view rootview) { mcam = camera.open(cameraid); if (mcam != null) { mcampreview = new mirrorview(rootview.getcontext(), mcam); mcampreview.getholder().setfixedsize(size, (size / 4) * 3); mcampreview.setcameradisplayorientationandsize(getactivity(), cameraid); layout.addview(mcampreview); } } }
how can refresh mapview without touching it?
Comments
Post a Comment