2016-02-25 7 views
7

新しいサポートライブラリでは以前はAPI 21+でのみサポートされていたアニメーションベクターがサポートされるようになりました。サポートライブラリを最新バージョンにアップグレードしました。<animated-vector>にはAPIレベル21が必要です(現在の最小値は15です)

Android Studioではまだ警告が表示されています。アニメーションベクターにはAPIレベル21(現在の最小値は15)が必要です。

私は以下でした:

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' 

} 

マイアニメーション:

私はbuild.gradleには、以下のコードを追加:だから今、私のbuild.gradleファイルは次のように

defaultConfig { 
    generatedDensities = [] 

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

に見えますドロワブル:

<?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 
+0

コードは実行されますか?私は警告が新しいアプリケーションを使用するときに与えられていることに気づいた:xmlのsrcCompat属性も。しかし、それは単に糸くずチェックに失敗し、コードが実行されます。彼らは次のスタジオのリリースでそれを修正する可能性が高いです。 – Jahnold

+0

アレックスは既に答えました。はい、app:srcCompatを使用すると警告が表示されますが、警告を無視してスタジオの更新を待つ必要があるようです。 – SMahdiS

答えて

9

私はこれをテストしました。できます! 私はベクトル描画可能なアニメーションやレイアウトにこれを追加作成しました:

<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:srcapp:srcCompatに置き換え、プレビューが壊れました。しかし、このアプリは、Android 4.0の電話機とアニメーション作品から始まりました。

結論:サポートライブラリが動作します。 Androidスタジオ(1.5.1)はまだ準備ができていません。

+1

ベクターをどのディレクトリに保存しましたか? drawable-v21かdrawableか? – Codeversed

+1

私はそれらをdrawable –

関連する問題