使用Zxing库,Xamarin.android应用程序扫描时,将屏幕方向锁定为纵向。

时间:2015-09-30 08:23:46

标签: c# android visual-studio xamarin zxing

我已经看到它可以在相机配置管理器中完成,但不知道在哪里可以找到该文件???

我已添加:

          <activity android:name="MainActivity"

          android:configChanges="keyboardHidden|orientation" 

          android:screenOrientation="portrait"/>

现在主要活动被锁定在肖像上,但是当从内部活动运行zxing扫描仪时,屏幕会在扫描期间旋转吗?

2 个答案:

答案 0 :(得分:5)

将此添加到您的主要活动以锁定方向

[Activity (Label = "YourLabel", MainLauncher = true, ScreenOrientation = Android.Content.PM.ScreenOrientation.Landscape)]

要使用代码更改方向,请使用:

if (scanning)
    RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;

答案 1 :(得分:3)

我已经解决了这个问题,最后很简单。我正在使用Zxing.net.mobile,而不是zxing.net,这有点不同......

            var scanner = new MobileBarcodeScanner();
            scanner.TopText = "Scanning for Barcode...";
            var result = await scanner.Scan(new MobileBarcodeScanningOptions
            {
                AutoRotate = false
            });
            if (result != null)
            {
                _scan.ScanValue = result.ToString();
                _scan.Action = "Scan";
                await CallService();
            }
            else
            {
                scanner.Cancel();
                Recreate();
            }
        };

这很有效。