android - MapFragment and Camera seem to interfere with each other in the same Activity -


i'm trying use mapfragment google maps android api v2 in conjunction camera preview. need able switch between camera preview , mapfragment, can’t make work.

for camera preview, i’ve copied camerapreview class example guide. when want see camera preview, add instance of camerapreview class activity using

camerapreview mpreview = new camerapreview(this);  addcontentview(mpreview, new layoutparams(layoutparams.match_parent,layoutparams.match_parent)); 

this works fine when when i’m not using mapfragment.

for mapfragment, i’ve added activity’s layout via

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/activity_main"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     tools:context=".mainactivity" >       <fragment         android:id="@+id/map"         android:layout_width="fill_parent"         android:layout_height="match_parent"         class="com.google.android.gms.maps.mapfragment" />  </linearlayout>  

it works fine without camerapreview. can hide , unhide mapfragment using (e.g. hide):

fragmenttransaction ft = getfragmentmanager().begintransaction(); ft.hide(map_fragment); ft.commit(); 

however, problem comes when try , use 2 together, i.e. hide mapfragment , add camerapreview instance activity. hide doesn’t work, , seems mapfragment somehow hijacks camerapreview , takes precedence. 1 strange feature if force screen sleep , wake up, when wakes camerapreview there. if other way round, i.e. add camerapreview first , hide mapfragment, behavior same.

fyi: i'm testing app on samsung galaxy note 2 lte running android version 4.1.1.

can tell me i’m doing wrong?

use setzorderontop(boolean) on camerapreview mpreview.setzorderontop(true);. works me.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -