1

Im using the following code to show the camera view within a layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:opencv="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    android:orientation="vertical"
    android:weightSum="2">

    <RelativeLayout
        android:id="@+id/cam_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary">

        </LinearLayout>

        <org.opencv.android.JavaCameraView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="visible"
            android:id="@+id/AddPersonPreview"
            opencv:show_fps="false"
            opencv:camera_id="any" />

    </RelativeLayout>


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="0">

    </LinearLayout>

</LinearLayout>

Im trying to have the camera view to occupy full width and full height as that of the cam_frame. It occupies the height but the width of the frame is not fully occupied and hence there is a black background alongside the width. How can I be able to sort this out?

1 Answers1

0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:orientation="vertical">

<RelativeLayout
    android:id="@+id/cam_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary">

    </LinearLayout>

    <org.opencv.android.JavaCameraView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible"
        android:layout_margin="30dp"
        android:id="@+id/AddPersonPreview"
        opencv:show_fps="false"
        opencv:camera_id="any" />

</RelativeLayout>

</LinearLayout>
phatnhse
  • 3,870
  • 2
  • 20
  • 29