3

棒棒糖之前的设备现在可以通过支持库 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" />

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

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

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

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

这就是我在 Android 4.3 上得到的结果: 在此处输入图像描述

和安卓 5.1: 在此处输入图像描述

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

4

2 回答 2

4

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

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

于 2016-03-10T11:31:15.097 回答
0

“为标签 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" />
于 2016-03-05T13:29:15.080 回答