surface java程序,Java-通过SurfaceView使用Zxing条形码阅读器

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

我应该如何创建类似的应用程序,主要问题是如何将zxing设置为Surface.

如果有什么办法,我将不胜感激.

布局截图:

aea03e165888978a36f42135648e0886.png

解决方法:

使用以下代码自定义zxing布局.

我在这里带了一个用于Zxing Scanner的RelativeLayout.

或者,使用以下引用:

我的设计如下图所示,如果需要,可以采用FrameLayout.

c46940a54474db75d9d753fc805af9b8.png

Xml代码:

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="wrap_content">

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">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

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" />

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" />

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" />

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">

android:layout_alignParentBottom="true"

android:layout_width="match_parent"

android:background="@color/colorPrimaryDark"

android:layout_height="120dp"

android:orientation="horizontal">

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" />

活动代码:(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);

}

标签:barcode-scanner,zxing,surfaceview,java,android

来源: https://codeday.me/bug/20191109/2012545.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值