如何ZXING条码扫描器不是全屏只有半屏 [英] How to ZXING Barcode Scanner not full screen only half screen

查看:211
本文介绍了如何ZXING条码扫描器不是全屏只有半屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建应用程序 使用ZXING条形码扫描仪扫描条形码

I want create application Scan Barcode using ZXING Barcode Scanner

像Blackberry Messenger

Like Blackberry Messenger

这是我的代码" MainActivity.java "

package com.example.ridwan.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import info.vividcode.android.zxing.CaptureActivity;
import info.vividcode.android.zxing.CaptureActivityIntents;

public class MainActivity extends AppCompatActivity  {

    private TextView tvScanResult;

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

        Intent captureIntent = new Intent(MainActivity.this, CaptureActivity.class);
        CaptureActivityIntents.setPromptMessage(captureIntent, "Barcode scanning...");
        startActivityForResult(captureIntent, 0);

        tvScanResult = (TextView) findViewById(R.id.tv_scanresult);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0) {
            if (resultCode == Activity.RESULT_OK && data != null) {
                String value = data.getStringExtra("SCAN_RESULT");
                tvScanResult.setText(value);
            } else if (resultCode == Activity.RESULT_CANCELED) {
                tvScanResult.setText("Scanning Gagal, mohon coba lagi.");
            }
        } else {

        }
        super.onActivityResult(requestCode, resultCode, data);
    }


}

然后这是我的" 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: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.ridwan.myapplication.MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_marginTop="50dp"
        android:id="@+id/tv_scanresult_title"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Result Scan : " />

    <TextView
        android:layout_below="@id/tv_scanresult_title"
        android:id="@+id/tv_scanresult"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:textColor="#ff1493"
        android:layout_height="wrap_content"
        android:text="_" />

</RelativeLayout>

您能给我解决方法吗? 我想在片段中条形码.

Can you give me solution ? i want to barcode in fragment.

推荐答案

通过使用 ZXing Android Embedded .实施起来非常简单-而且还包括割炬功能.

I have achieved the same effect/UI you are looking for by using ZXing Android Embedded. Very straightforward to implement - and it also includes a torch functionality.

这篇关于如何ZXING条码扫描器不是全屏只有半屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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