如何在Zxing Scanner相机视图中添加按钮 [英] How to add buttons in Zxing Scanner Camera View

查看:97
本文介绍了如何在Zxing Scanner相机视图中添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的Zxing扫描仪屏幕如下所示,

my current Zxing scanner screen looks like this,

我想在其上添加一个textview和几个按钮,我尝试了许多过程,但是没有任何工作可以指导我,我将很谦虚地期待您的帮助

I want to add a textview and couple of buttons on it, I had tried many procedures but nothing worked can anyone guide me, I will be humbly looking forward for your kind help

这是代码

Java文件:

    private ZXingScannerView mScannerView;
    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        setContentView(R.layout.activity_qrresult);
        mScannerView = new ZXingScannerView(this); 
        setContentView(mScannerView);              


    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this); 
        mScannerView.startCamera();          
        Toast.makeText(getApplicationContext(),"Scan QR code to Send 
     Money",Toast.LENGTH_LONG).show();
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        // Do something with the result here
        if(rawResult.getText().toString().equals("Test Ewallet Test")){
            Toast.makeText(getApplicationContext(), rawResult.getText(), 
    Toast.LENGTH_SHORT).show();
            Intent go = new Intent(qrresult.this,sendmoney.class);
            startActivity(go);

        }else {
            Toast.makeText(getApplicationContext(), "Couldn't scan the 
     QRcode, Please Try again ", Toast.LENGTH_SHORT).show();

            mScannerView.resumeCameraPreview(this);
        }



        // mScannerView.resumeCameraPreview(this);

        // If you would like to resume scanning, call this method below:
        //mScannerView.resumeCameraPreview(this);
    }
}

这是xml文件

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tajveezrehman.applicationtest.yourqr">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <Button
        android:id="@+id/flashlight"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.8"
        android:text="Button" />

    <Button
        android:id="@+id/open image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.8"
        android:text="Button" />

    <TextView
        android:id="@+id/camtxt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:layout_weight="0.8"
        android:text="@string/scanner"
        android:textAlignment="center"
        android:textColor="#000000"
        android:textSize="20sp" />

  </LinearLayout>

 </RelativeLayout>

推荐答案

像这样使用 RelativeLayout :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<me.dm7.barcodescanner.zxing.ZXingScannerView
    android:id="@+id/zxscan"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   />

<ImageView
    android:id="@+id/btn_flash"
    android:layout_marginBottom="15dp"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:src="@drawable/flash_100"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

它看起来像:

这篇关于如何在Zxing Scanner相机视图中添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆