Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

JavaCameraView preview not fullscreen


I would like to know how to make the preview of fullscreen while on resolutions lower than the native screen resolution. (I´m trying to get 640x480). Right now the preview is a small square in the center of the screen. The device supports 640x480 both as Camera resolution and Preview resolution.

Before posting the question here, I did some research and wasn´t able to find any solutions. Let me explain what I have tried so far:

First, this is what I have:

  • Instead using CameraBridgeViewBase, I'm using a custom class, which extends JavaCameraView in order to be able to change the camera resolution.
public class JavaCamResView extends JavaCameraView {

public JavaCamResView(Context context, AttributeSet attrs) {
    super(context, attrs);

public List<Camera.Size> getResolutionList() {      
    return  mCamera.getParameters().getSupportedPreviewSizes();  
    //return  mCamera.getParameters().getSupportedPictureSizes();

public void setResolution(Camera.Size resolution) {
    connectCamera((int)resolution.width, (int)resolution.height);      


public void setFocusMode (Context item, int type){

public void setFlashMode (Context item, int type){

public Camera.Size getResolution() {

    Camera.Parameters params = mCamera.getParameters(); 

    Camera.Size s = params.getPreviewSize();
    return s;


<RelativeLayout xmlns:android=""
android:layout_height="match_parent" >

    android:layout_height="fill_parent" />


Finally the resolution is set inside the Activity onCameraViewStarted method:

public void onCameraViewStarted(int width, int height) {
    mRgba = new Mat(height, width, CvType.CV_8UC3);

    mResolutionList = mOpenCvCameraView.getResolutionList();

    for(Camera.Size resolution:mResolutionList){
        if(resolution.width == 640){


What I have tried so far:

  • added on onCreate: getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

  • added to Manifest: <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" />

  • mOpenCvCameraView.setMaxFrameSize(maxWidth, maxHeight)

  • Enclosing JavaCameraView layout inside a FrameLayout alone (instead of RelativeLayout) is not an option, since I need to show things on top of the preview.

Still no luck...

I´ve tried the code on different devices with same result (Current device is a Samsung SIII NEO, Android 4.4.2)

Thanks in advance!

Best regards