I am very new to Android development and I am trying to get a simple app setup for the camera. So far I have a camera application that has the “camera switch” and “snapshot” buttons inside the menu that work fine.
The only problem I am facing is that I am trying to figure out how to get the screen in full screen. Right now, the camera appears only in the very middle of the screen and occupies approximately 1/4 of the screen.
MainActivity Code
package assist.core; import android.app.Activity; import android.app.AlertDialog; import android.hardware.Camera; import android.hardware.Camera.PictureCallback; import android.hardware.Camera.ShutterCallback; import android.hardware.Camera.CameraInfo; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.util.Log; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class MainActivity extends Activity { private final String TAG = "MainActivity"; private Preview mPreview; Camera mCamera; int numberOfCameras; int cameraCurrentlyLocked;
Class Code Preliminary Code
package assist.core; import android.content.Context; import android.hardware.Camera; import android.hardware.Camera.Size; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import java.util.List; import java.io.IOException; class Preview extends ViewGroup implements SurfaceHolder.Callback { private final String TAG = "Preview"; SurfaceView mSurfaceView; SurfaceHolder mHolder; Size mPreviewSize; List<Size> mSupportedPreviewSizes; Camera mCamera; Preview(Context context) { super(context); mSurfaceView = new SurfaceView(context); addView(mSurfaceView);
camer_menu.xml code
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <item android:id="@+id/switchCam" android:title="@string/switch_cam" /> <item android:id="@+id/takePicture" android:title="@string/take_picture" android:onClick="snapPicture" android:layout_gravity="center" /> </menu>
UPDATE
I tried changing the code in the Preview constructor to the following.
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); this.setLayoutParams(lp); mSurfaceView = new SurfaceView(context); mSurfaceView.setLayoutParams(lp); addView(mSurfaceView);
This did not work, but also did not make the camera full screen.
Metropolis
source share