通过 surfaceview 使用 zxing 条形码 reader

using zxing barcode reader through surfaceview

我正在创建一个 Barcode Scanner 应用程序,我想使用 Zxing 来读取条码,我的应用程序有一个 surfaceview 并在其中显示相机,但现在我想从我的 SurfaceView 相机扫描条形码,我使用它的原因是我在布局的表面视图下有两个 Edittext 来显示条形码的内容.

我应该如何创建一个应用程序,主要问题是如何将 zxing 设置到表面。
如果有任何办法,我将不胜感激。

布局截图:

使用以下代码自定义您的 zxing 布局。

我在这里拍了一个RelativeLayout zxing Scanner

或者,使用以下参考文献:

我的设计如下图,有需要的可以拍FrameLayout

Xml代码:

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




<android.support.v7.widget.Toolbar
    android:id="@+id/toolbarAdjustScan"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@color/colorPrimary"
    android:elevation="6dp"
    android:minHeight="56dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/titleToolbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:ellipsize="end"
            android:layout_weight="1"
            android:maxLines="1"
            android:textColor="@color/white"
            android:textSize="18dp" />

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:padding="10dp"
            android:id="@+id/searchAdjustBtn"
            android:layout_marginLeft="15dp"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="SEARCH   "
            android:textColor="@color/white"
            android:textSize="13dp" />
    </LinearLayout>

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


 <TextView
    android:id="@+id/textv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:gravity="center_horizontal"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
    android:text="Point at any barcode to scan"
    android:textColor="@color/white"
    android:textSize="14sp"
    android:textStyle="normal" />

<RelativeLayout
    android:layout_marginBottom="120dp"
    android:layout_below="@+id/textv"
    android:id="@+id/relative_scan_take_single"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</RelativeLayout>
</LinearLayout>

<LinearLayout
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:background="@color/colorPrimaryDark"
    android:layout_height="120dp"
    android:orientation="horizontal">

    <Button
        android:id="@+id/doneBtn"
        style="@style/Widget.AppCompat.Button.Colored"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_gravity="bottom"
        android:text="Done"
        android:textAllCaps="true"
        android:textColor="@color/white"
        android:textSize="22dp" />


</LinearLayout>

Activity代码:(Java)

   public class TakeSingleScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
    private ZXingScannerView mScannerView;



 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_take_single_scan);

 //Scanner
        mScannerView = new ZXingScannerView(this);
        RelativeLayout rl = (RelativeLayout) findViewById(R.id.relative_scan_take_single);
        rl.addView(mScannerView);
        mScannerView.setResultHandler(this);
        mScannerView.startCamera();
        mScannerView.setSoundEffectsEnabled(true);
        mScannerView.setAutoFocus(true);

    }