Camera preview in xml

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Camera preview in xml

Postby tinyang » Sun Aug 23, 2009 2:07 pm

Hello.

I am trying to put my camera preview on a surfaceview inside an xml layout, but I'm not having any luck. I am doing this in the emulator, and I have my camera preview working (I know because I get the checkerboard with the square moving in it), but it just appears in the top left corner of the screen instead of inside the activity screen where I would like it to be. Here is a link to an example of where I would like it to be: example

Can anyone help please?

Below is my xml and associated java code:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7.    
  8.     <TextView
  9.         android:id="@+id/pictitle"
  10.        android:layout_width="fill_parent"
  11.        android:layout_height="wrap_content"
  12.        android:layout_marginTop="10dip"
  13.        android:text="Take a Picture"
  14.    />            
  15.                         <SurfaceView android:id="@+id/camsurface"
  16.                                                  android:layout_width="fill_parent"
  17.                                                  android:layout_height="10dip"
  18.                                                  android:layout_weight="1">
  19.                         </SurfaceView>
  20.                        
  21.         <Button android:id="@+id/snapshot"
  22.         android:layout_width="wrap_content"
  23.        android:layout_height="wrap_content"
  24.        android:layout_below="@id/space"
  25.        android:layout_centerHorizontal="true"
  26.        android:text="        Snapshot         " />
  27.  
  28. </LinearLayout>
  29.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         setContentView(camPreview); //set preview as activity content
  2.         camSurface = (SurfaceView) findViewById(R.id.camsurface);
  3.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
--
Moderation is the key to happiness and harmony in one's life.
User avatar
tinyang
Freshman
Freshman
 
Posts: 6
Joined: Sat Jan 03, 2009 4:50 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests