android - 在 API 21+ 上使用带有 srcCompat 的 VectorDrawables 将 Android 支持库更新到 23.2.0

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

很高兴 Lollipop 之前的设备现在可以通过支持库 23.2.0 使用 VectorDrawables。虽然我在 API 21+ 上有图像显示问题,但在低端设备上一切正常。我使用的是 Gradle Plugin 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" />

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

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

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

"Unexpected namespace prefix "app" found for tag ImageView"

这是我在 Android 4.3 上得到的结果: enter image description here

和安卓 5.1: enter image description here

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

最佳答案

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

(您现在可以安全地忽略该 Lint 错误,同时将 tools:ignore="MissingPrefix" 添加到您的 ImageView)。

关于android - 在 API 21+ 上使用带有 srcCompat 的 VectorDrawables 将 Android 支持库更新到 23.2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35814680/

相关文章:

android - findViewById 返回错误的元素?

Android - 更改 ImageView 可绘制对象消耗的内存过多

Android - 更新支持库 com.android.support :cardview-v7 to version 27. 0.2 未知属性问题

android - 无法安装Android支持库22.0.1

android - android-support-v7-appcompat 和 android-support-v4 之间的区别

android - Android 设备上的 JavaPos?

android - 默认FirebaseApp未初始化

Android listview项目背景改变

android - 通过 Zoom、Android 缩放 map 标记

android - ScrollView 中的第一个嵌入式 ImageView 未显示