【问题标题】:ZXingBarcodeImageView (QR code) showing on iOS but not on Android (Xamarin.Forms)ZXingBarcodeImageView(QR 码)在 iOS 上显示但在 Android 上不显示(Xamarin.Forms)
【发布时间】:2018-03-05 08:12:14
【问题描述】:

这段用于在 Xamarin.Forms 应用中显示 QR 码的代码适用于 iOS,但不适用于 Android:

let barCode = ZXingBarcodeImageView(HorizontalOptions = LayoutOptions.FillAndExpand,
                                    VerticalOptions = LayoutOptions.FillAndExpand,
                                    BarcodeFormat = ZXing.BarcodeFormat.QR_CODE,
                                    BarcodeValue = foo)
barCode.BarcodeOptions.Width <- 500
barCode.BarcodeOptions.Height <- 500
mainLayout.Children.Add(barCode)

日志中没有错误,没有抛出异常。尝试了许多高度和宽度以及不同的 LayoutOptions 无济于事。我该如何调试?

【问题讨论】:

标签: xamarin xamarin.forms f# xamarin.android qr-code


【解决方案1】:

幸运的是,我只需要在自己的 Xamarin.Forms 项目中使用 ZXing.Net.Mobile。我设法使用下一个 C# 代码显示 iOS 和 Android 的 QRCode:

ZXingBarcodeImageView GenerateQR(string codeValue)
{
    var qrCode = new ZXingBarcodeImageView
    {
        BarcodeFormat = BarcodeFormat.QR_CODE,
        BarcodeOptions = new QrCodeEncodingOptions
        {
            Height = 350,
            Width = 350
        },
        BarcodeValue = codeValue,
        VerticalOptions = LayoutOptions.CenterAndExpand,
        HorizontalOptions = LayoutOptions.CenterAndExpand
    };
    // Workaround for iOS
    qrCode.WidthRequest = 350;
    qrCode.HeightRequest = 350;
    return qrCode;
}

请注意这个库中有一个知道issue,你必须明确设置WidthRequest & HeightRequest。

P.S.:here 也讨论了或多或少相同的问题。

【讨论】:

    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多