【问题标题】:Update Android Support Library to 23.2.0 using VectorDrawables with srcCompat on API 21+在 API 21+ 上使用 VectorDrawables 和 srcCompat 将 Android 支持库更新到 23.2.0
【发布时间】:2016-03-05 13:22:03
【问题描述】:

棒棒糖之前的设备现在可以通过支持库 23.2.0 使用 VectorDrawables 真是太好了。虽然我在 API 21+ 上有图像显示问题,但在较低的设备上一切正常。我使用的是 Gradle 插件 1.5,所以我的 build.gradle 包含以下内容:

// Gradle Plugin 1.5  
 android {  
   defaultConfig {  
     generatedDensities = []  
  }  

  // This is handled for you by the 2.0+ Gradle Plugin  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
 }  

然后我在布局中使用下一个代码:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/my_vector_drawable" />

我已经在我父母的 ViewGroup 中声明了这个属性:

xmlns:app="http://schemas.android.com/apk/res-auto"

但 Android Studio 仍然显示此错误,但项目可以构建和运行

“为标签 ImageView 找到了意外的命名空间前缀“app””

这是我在 Android 4.3 上得到的结果:

和 Android 5.1:

这是新支持库的错误还是我做错了什么?

【问题讨论】:

    标签: android android-imageview android-support-library android-vectordrawable


    【解决方案1】:

    为了解决您的图像缩放问题,您是否尝试将scaleType='fitXY' 设置为您的 ImageView?

    (您现在可以放心地忽略 Lint 错误,也可以将 tools:ignore="MissingPrefix" 添加到您的 ImageView)。

    【讨论】:

      【解决方案2】:

      “为标签 ImageView 找到了意外的命名空间前缀“app””

      您必须在布局中声明命名空间(通常在根元素中):

      <ImageView
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:srcCompat="@drawable/my_vector_drawable" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-08
        • 2016-08-12
        • 1970-01-01
        • 2016-03-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多