其他分享
首页 > 其他分享> > 如何设置扫描区域ZXing扫描仪

如何设置扫描区域ZXing扫描仪

作者:互联网

您好我在Android Studio中使用ZXING Scanner创建了Reader QR码

我想增加高度和宽度扫描区域绿色边框看到这个图像.

enter image description here

你有解决方案来设置高度和宽度扫描区域(绿色边框)吗?

这是我的代码MainActivity.java

package com.example.gajelo.barcodereader;

import android.widget.RelativeLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;


public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler  {

    private ZXingScannerView mScannerView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_main);
        mScannerView = new ZXingScannerView(this);
        RelativeLayout rl = (RelativeLayout) findViewById(R.id.relative_scan);
        rl.addView(mScannerView);
        mScannerView.setResultHandler(this);
        mScannerView.startCamera();
    }
    @Override
    protected void onPause() {
        super.onPause();
        mScannerView.stopCamera();
    }

    @Override
    public void handleResult(Result result) {
        Log.w("handleResult", result.getText());
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setMessage(result.getText());
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}

CaptureFragment.java

package com.example.gajelo.barcodereader;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.os.Bundle;
import me.dm7.barcodescanner.zxing.ZXingScannerView;

public class CaptureFragment extends Fragment {
    private ZXingScannerView mScannerView;
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
        View view = inflater.inflate(R.layout.capture, container, false);
        return view;
    }
}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.gajelo.barcodereader.MainActivity">

    <TextView
        android:text="This Is Main Activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView2"
        android:textSize="30sp"
        android:textStyle="normal|bold"
        android:textColor="@android:color/black"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="22dp" />

    <TextView
        android:text="Scan QR CODE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:textSize="30sp"
        android:textStyle="normal|bold"
        android:textColor="@android:color/black"
        android:layout_alignParentBottom="true"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignStart="@+id/textView2"
        android:layout_marginLeft="23dp"
        android:layout_marginStart="23dp"
        android:layout_marginBottom="54dp" />

    <RelativeLayout
        android:id="@+id/relative_scan"
        android:layout_width="300dip"
        android:layout_height="300dip"
        android:layout_centerInParent="true"
        android:layout_gravity="center">

    </RelativeLayout>

</RelativeLayout>

capture.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">
</RelativeLayout>

解决方法:

您可以使用
  应用程式:zxing_framing_rect_width = “200dp”
和app:zxing_framing_rect_height =“200dp”增加高度

<com.journeyapps.barcodescanner.DecoratedBarcodeView
    android:id="@+id/zxing_barcode_scanner"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="36dp"
    app:zxing_framing_rect_width="200dp"
    app:zxing_framing_rect_height="200dp"
    app:zxing_preview_scaling_strategy="fitXY"
    app:zxing_use_texture_view="false"
    />

标签:java,android,xml,zxing,barcode-scanner
来源: https://codeday.me/bug/20190710/1428896.html