2016-08-01 91 views
0

我想顯示掃描儀在一個小區域,而不是全屏,在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" /> 

等爲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())

回答

0

我已經做了一些非常相似的事情,但使用了不同的方法。我將ZXing直接集成到我的應用程序中。然後我用在這裏找到

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

到我的類模型關閉的類。要修改的重要代碼是在和的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); 
} 

線的東西。

+0

他使用'Zxing.Net.Mobile'而不是'zxing/zxing' –