jassim
jassim

Reputation: 49

CameraSourcePreview doesn't fill whole screen height

I have (Camera Source Preview) does't cover the whole screen, inside (Camera source Preview) there is (Image View) seems hiding behind the (Camera Source Preview), my point that i need The (Camera Source Preview) Cover whole Screen, and the Image View in front of it.

MainLayout

    <com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview
            android:id="@+id/preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay
                android:id="@+id/faceOverlay"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview>

        <ImageView
            android:id="@+id/btn_change_camera"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="end"
            android:layout_marginEnd="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:clickable="true"
            android:contentDescription="@string/img_desc_btn_change_camera"
            android:focusable="true"
            android:scaleType="fitXY"
            android:src="@drawable/ic_change_camera" />

        <ImageView
            android:id="@+id/btn_capture"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="bottom|center_horizontal"
            android:layout_marginBottom="20dp"
            android:clickable="true"
            android:contentDescription="@string/img_desc_btn_capture"
            android:focusable="true"
            android:scaleType="fitXY"
            android:src="@drawable/ic_capture" />

Screenshot

Upvotes: 1

Views: 1356

Answers (1)

Faisal
Faisal

Reputation: 772

For the CameraSourcePreview to cover the whole screen you'll have to change some code in your CameraSourcePreview.java file like,

Inside your onLayout method,

// Computes height and width for potentially doing fit width.
    int childWidth = layoutWidth;
    //int childHeight = (int)(((float) layoutWidth / (float) width) * height);
    int childHeight = layoutHeight;

Then in your barcodeCaptureActivity, find createCameraSource method, and comment out setRequestedPreviewSize like below.

    CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
            .setFacing(CameraSource.CAMERA_FACING_BACK)
            //.setRequestedPreviewSize(1600, 1024)
            .setRequestedFps(15.0f);

Now you can see your CameraSourcePreview full screen.

Upvotes: 3

Related Questions