为了在我的android项目中使用SVG文件,我必须使用vector compat。
首先,我根据http://a-student.github.io/SvgToVectorDrawableConverter.Web/
将我的SVG文件转换为矢量然后我关注了官方博客http://android-developers.blogspot.fr/2016/02/android-support-library-232.html
所以这是我的build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "xxx"
minSdkVersion 16
targetSdkVersion 22
versionCode 22
versionName "2.0"
vectorDrawables.useSupportLibrary = true
}
[...]
}
在我的xml中我用这个
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_grey"
tools:ignore="MissingPrefix">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/login_margin">
<ImageView
android:id="@+id/info_about_app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/back_login"
app:srcCompat="@drawable/vector"/> <-- Important line
我的矢量看起来像
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:width="425dp"
android:height="252dp"
android:viewportHeight="504"
android:viewportWidth="850"
auto:height="252dp"
auto:viewportHeight="504"
auto:viewportWidth="850"
auto:width="425dp"
tools:ignore="NewApi">
<group
android:translateY="-548.3622"
auto:translateY="-548.3622">
在Android Studio中预览没问题,但是当我尝试运行我的应用时,我收到以下错误
Error:(2) No resource identifier found for attribute 'viewportHeight' in package 'xxx'
我认为这个错误是由于错误的ID后退,但它是
的作用vectorDrawables.useSupportLibrary = true
android plugin for gradle ==> 2.1.0-beta1
我该如何解决?
答案 0 :(得分:1)
只需删除此行:
auto:viewportHeight="504"
这是No resource identifier found for attribute 'viewportHeight'
建议我的。
或者您没有导入支持向量compat库 但我倾向于认为你做到了。