【问题标题】:Xamarin.Android : ZXing scanner from a small area (not fullscreen)Xamarin.Android:小区域的 ZXing 扫描仪(非全屏)
【发布时间】:2016-08-01 16:48:02
【问题描述】:

我想在一个小区域而不是全屏显示扫描仪,如 post here(但 Xamarin.Android 和 MvvmCross 在片段中)。

为此,我有我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto">
<FrameLayout
    android:id="@+id/barcodeview"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_weight="0">
    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#d13033"
        android:layout_gravity="center_vertical" />
</FrameLayout>
<Mvx.MvxListView
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    local:MvxItemTemplate="@layout/item_product"
    local:MvxBind="ItemsSource Products" />

喜欢http://imgur.com/a/t1sgq

还有我的片段视图:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    base.OnCreateView(inflater, container, savedInstanceState);
    var view = this.BindingInflate(Resource.Layout.Products, null);
    var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
    MobileBarcodeScanner.Initialize(activity.Application);
    var barcodeview = view.FindViewById<FrameLayout>(Resource.Id.barcodeview);

    var scanner = new ZXingScannerFragment();
    scanner.UseCustomOverlayView = true;
    scanner.CustomOverlayView = barcodeview;
    scanner.StartScanning(result =>
    {
        Mvx.Trace("Scanned with ZXingScannerFragment : " + result.Text);
    });
    //_mobileBarcodeScanner = new MobileBarcodeScanner();
    //_mobileBarcodeScanner.UseCustomOverlay = true;
    //_mobileBarcodeScanner.CustomOverlay = barcodeview;
    //_mobileBarcodeScanner.Torch(true);
    //_mobileBarcodeScanner.ScanContinuously(result =>
    //{
    //    Mvx.Trace("Scanned :" + result.Text);
    //});
    return view;
}

}

我尝试了 MobileBarcodeScanner 和 ZXingScannerFragment 类:

使用 MobileBarcodeScanner,扫描仪可以全屏启动并正常工作。

使用 ZXingScannerFragment,扫描仪不会启动。即使我使用FragmentManager.Replace(barcodeview, new ZXingScannerFragment()).Commit())

【问题讨论】:

    标签: android xamarin barcode zxing


    【解决方案1】:

    我做了一些与此非常相似的事情,但使用了不同的方法。我将 ZXing 直接集成到我的应用程序中。然后我使用了这里找到的类

    https://github.com/zxing/zxing/blob/master/android/src/com/google/zxing/client/android/CaptureActivity.java

    模仿我的班级。要修改的重要代码在 onResume 和 onPause 方法中,类似于

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
     } else {
            // Install the callback and wait for surfaceCreated() to init the camera.
         surfaceHolder.addCallback(this);
    }
    

    其中 R.id.preview_view 可以替换为您要使用的小区域视图。

    【讨论】:

    • 他使用的是Zxing.Net.Mobile而不是zxing/zxing
    猜你喜欢
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    相关资源
    最近更新 更多