Android扫码问题


version="1.0" encoding="utf-8"?>
android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".QrCodeActivity"
    android:orientation="vertical">

    id="@+id/decoratedBarcodeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:zxing_framing_rect_height="250dp"
        android:zxing_framing_rect_width="250dp"
        android:zxing_preview_scaling_strategy="fitXY"
        android:zxing_scanner_layout="@layout/layout_zxing"
        android:zxing_use_texture_view="true"

        />

img


这个问题的原因是什么?
我引入的依赖'com.journeyapps:zxing-android-embedded:3.3.0'

这个问题的原因可能是因为您的项目中引入了一个名为com.journeyapps:zxing-android-embedded:3.3.0的依赖,但是您的项目中没有使用该库。

自定义属性用app命名空间,不要用android。既然用了这个库,就好好看使用文档,我想文档上写的的不是“android:zxing_framing_rect_height”,应该是“app:zxing_framing_rect_height”

  • 给你找了一篇非常好的博客,你可以看看是否有帮助,链接:利用com.journeyapps:zxing-android-embedded:3.6.0实现扫码的问题
  • 除此之外, 这篇博客: 全网最全Android开发工具,Android开发框架大全中的 zxing-android-embedded 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 安卓条形码扫描库,使用ZXing用于解码。该项目松散地基于中兴安卓条形码扫描仪应用,但不隶属于正式的ZXing项目。特点:
    可以通过Intents使用(只需要很少的代码)。
    可以嵌入到活动中,用于用户界面和逻辑的高级定制。
    扫描可以在横向或纵向模式下进行。
    摄像机在后台线程中管理,以加快启动时间。
    示例应用程序可在中获得 Releases。
    默认情况下,安卓SDK 24+是必需的,因为中兴:核心3.4.0。要支持SDK 14+,请参见旧的SDK版本。
    地址:
    github
    https://github.com/journeyapps/zxing-android-embedded
    使用:
    Add the following to your build.gradle file:

    repositories {
        jcenter()
    }
    dependencies {
        implementation 'com.journeyapps:zxing-android-embedded:4.1.0'
        implementation 'androidx.appcompat:appcompat:1.0.2'
    }
    android {
        buildToolsVersion '28.0.3' // Older versions may give compile errors
    }
    

    For Android SDK versions < 24, you can downgrade zxing:core to 3.3.0 or earlier for Android 14+ support:

    repositories {
        jcenter()
    }
    dependencies {
        implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
        implementation 'androidx.appcompat:appcompat:1.0.2'
        implementation 'com.google.zxing:core:3.3.0'
    }
    android {
        buildToolsVersion '28.0.3'
    }
    

引入Zxing库