<animated-vector>需要API级别21(当前最小值为15)

SMa*_*diS 10 android

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

但是Android Studio仍然给我一个警告:动画矢量需要API级别21(当前最小值为15).

我做了以下事情:

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

defaultConfig {
    generatedDensities = []

}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
    additionalParameters "--no-version-vectors"
}
Run Code Online (Sandbox Code Playgroud)

所以现在我的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'

}
Run Code Online (Sandbox Code Playgroud)

我的动画可绘:

<?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>
Run Code Online (Sandbox Code Playgroud)

在动画drawable的第一行,它说:动画矢量需要API级别21(当前最小值为15).

那有什么不对?

  [1]: http://android-developers.blogspot.com/2016/02/android-support-library-232.html
Run Code Online (Sandbox Code Playgroud)

Ale*_*tko 14

好.我测试了这个.有用!我创建了动画矢量drawable并将其添加到布局:

<ImageView
    android:id="@+id/animated"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    app:srcCompat="@drawable/animated" />
Run Code Online (Sandbox Code Playgroud)

这要代码:

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

安卓工作室在预览中向我显示这个可绘制的但是app在启动时崩溃了(Android 4.0手机)

然后我替换android:srcapp:srcCompat,预览变得破碎.但这个应用程序开始于Android 4.0手机和动画作品.

结论:支持库工作.Android studio(1.5.1)还没有准备好.