Skip to content

camera preview is stretched pretty much in this layout #16

@roostaamir

Description

@roostaamir

Hi again
I've been busy with your library this past couple of days and unfortunately, I faced another problem
I have this layout file:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <LinearLayout
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#00000000"
            android:layoutDirection="rtl">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:minHeight="?attr/actionBarSize"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:titleTextColor="@android:color/white"
                android:background="?attr/colorPrimary">

                <TextView
                    android:id="@+id/toolbar_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="title"
                    android:textColor="@android:color/white"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                    android:layout_gravity="center"
                    android:typeface="monospace"/>

            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:layoutDirection="ltr"
                android:layout_width="wrap_content"
                android:layout_height="80dp"
                android:layout_gravity="center_horizontal"
                android:background="#ebeff2"
                app:tabMode="scrollable"
                app:tabGravity="fill"
                app:tabIndicatorColor="@android:color/black"
                android:id="@+id/tabLayout_categories"
                style="@style/MyCostumeTabLayout"/>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:layoutDirection="ltr"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/viewPager_tabs"
            android:layout_gravity="center"/>

    </LinearLayout>

    <!-- this is the root layout for the barcode scanner -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/frameLayout_camera_root" />
</FrameLayout>

As you can see I did this so that the barcode scanner is on top of other layouts. ( I am trying to make this layout look like a dialog)
this is my java code and how I start the barcode scanner (for now this code is in the onCreate method of the activity):

@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_barcode);
        showBarcodeScanner();
    }

private void showBarcodeScanner() {
        prepareBarcodeScanner();
        getSupportFragmentManager().beginTransaction().add(R.id.frameLayout_camera_root, barcodeCaptureFragment).commit();
    }

private void prepareBarcodeScanner() {
        barcodeCaptureFragment = BarcodeCaptureFragment.instantiate(
                MVBarcodeScanner.ScanningMode.SINGLE_AUTO, formats);
        scanningListener = new BarcodeCaptureFragment.BarcodeScanningListener() {
            @Override
            public void onBarcodeScanned(Barcode barcode) {
               //do something
            }

            @Override
            public void onBarcodesScanned(List<Barcode> barcodes) {
            }

            @Override
            public void onBarcodeScanningFailed(String reason) {
            }
        };
        barcodeCaptureFragment.setListener(scanningListener);
    }

the problem is that with this method, the camera preview is stretched (it still captures the barcodes and all, but the barcode is not on the screen at all when it is being captured, since the preview is stretched).
So how can I fix this?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions