Search code examples
androidsurfaceviewpreview

Add a Camera Preview


I want my Activity background to be the Camera(Back) view,I have so far tried to add a surfaceView but no luck,the tutorials I found were for opening the camera app. P.S- I do want to add more resources over the SurfaceView/Camera. & I don't want to click a picture only the preview As I do not have any code to show as they are not what I need,so here is the next best thing though it may have not been necessary.


Solution

  • have you tried something like this?

     <?xml version="1.0" encoding="utf-8"?>
     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent" android:layout_height="match_parent">
    
    
          <SurfaceView
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    
       <!--views on top should come after the surfaceview, 
       at the same level    in the view heirarchy.
       this gives them a higher z-index (i.e. drawn afterwards)
       ... you could also use a RelativeLayout as the root view -->
    
          <ImageView
          android:layout_width="100dp"
          android:layout_height="100dp" 
          android:layout_gravity="center"/>
    
    
    
     </FrameLayout>