<animated-vector> 需要API 21及以上版本(当前最低版本为15)

13

在[这里][1]提到新的支持库现在支持动画向量,这之前只在API 21+上被支持。我将支持库升级到了最新版本。

但是Android Studio仍然给出警告:animated-vector需要API级别21(当前最低为15)。

我做了以下操作:

我在build.gradle中添加了以下代码:

defaultConfig {
    generatedDensities = []

}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
    additionalParameters "--no-version-vectors"
}

现在我的 build.gradle 文件看起来像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.mahdi.askhow"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    generatedDensities = []

}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
    additionalParameters "--no-version-vectors"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.wang.avi:library:1.0.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile project(':phoenix')
    compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.3'

}

我的动画可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/vector_upvote">

    <target
        android:name="rotationGroup"
        android:animation="@anim/rotate_a_to_b" />


    <target
        android:name="left_arrow"
        android:animation="@animator/animator_checkmark" />
</animated-vector>

在动画绘制的第一行中,它说:animated-vector需要API级别21(当前最低级别为15)。

那么问题出在哪里?

  [1]: http://android-developers.blogspot.com/2016/02/android-support-library-232.html

代码能运行吗?我注意到在使用xml中的新app:srcCompat属性时会出现警告。然而,这只是一个失败的lint检查,代码可以运行。他们很可能会在下一个studio版本中修复它。 - Jahnold
Alex已经回答了。是的,在使用app:srcCompat时仍然存在警告,看来我们必须忽略这个警告并等待studio的更新。 - SMahdiS
1个回答

17

好的,我测试过了。它有效!我创建了动画矢量图并将其添加到布局中:

Ok. 我测试过了。IT WORKS! 我创建了animated vector drawable 并将其添加到layout中:

<ImageView
    android:id="@+id/animated"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    app:srcCompat="@drawable/animated" />

还有这段代码:

ImageView animatedView = (ImageView) findViewById(R.id.animated);
Drawable animation = animatedView.getDrawable();
if (animation instanceof Animatable) {
    ((Animatable) animation).start();
}

在Android 4.0手机上,Android Studio在预览中显示了此可绘制对象,但应用程序启动时崩溃。

然后我将android:src替换为app:srcCompat,预览变得不可用。但是此应用程序在Android 4.0手机上启动并且动画正常工作。

结论:支持库起作用。 Android Studio(1.5.1)尚未准备好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接