1
爲了在我的android項目中使用SVG文件,我必須使用vector compat。使用VectorDrawableCompat
首先,我根據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'
我認爲這個錯誤是由於不良的ids backport但它的作用
vectorDrawables.useSupportLibrary = true
android plugin for gradle ==> 2.1.0-beta1
我該如何解決這個問題?
'auto:'用於backport和'android:'用於API> 21。我不是sur我應該刪除 – mrroboaat
其中之一好吧,你是對的。 'auto:'必須被移除,否則你會得到這種錯誤(並且backport仍然有效)。 – mrroboaat