Xamarin.Android:ZXing扫描仪从一个小区域(非全屏)
问题描述:
我想显示扫描仪在一个小区域,而不是全屏,在post here(但Xamarin.Android和MvvmCross在片段)。Xamarin.Android:ZXing扫描仪从一个小区域(非全屏)
对于这一点,我有我的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" />
我的片段观点:
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())
。
答
我已经做了一些非常相似的事情,但使用了不同的方法。我将ZXing直接集成到我的应用程序中。然后我用在这里找到
到我的类模型关闭的类。要修改的重要代码是在和的onResume方法的onPause,沿着那里R.id.preview_view可以与您要使用的小区域视图替换的
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);
}
线的东西。
他使用'Zxing.Net.Mobile'而不是'zxing/zxing' –