gpt4 book ai didi

android - 使用 VectorDrawableCompat

转载 作者:行者123 更新时间:2023-11-30 01:24:16 28 4
gpt4 key购买 nike

为了在我的 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'

我认为这个错误是由于错误的 ids 向后移植造成的,但它是

的作用
vectorDrawables.useSupportLibrary = true

android plugin for gradle ==> 2.1.0-beta1

我该如何解决?

最佳答案

只需删除这一行:

auto:viewportHeight="504"

这就是 No resource identifier found for attribute 'viewportHeight' 给我的建议。

或者您没有导入支持向量兼容库。
但我倾向于认为你做到了。

关于android - 使用 VectorDrawableCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36661737/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com