2016-02-25 25 views
7

Nó được đề cập [ở đây] [1] rằng thư viện hỗ trợ mới hiện hỗ trợ vectơ hoạt hình, trước đây chỉ được hỗ trợ trong API 21+. Tôi đã nâng cấp thư viện hỗ trợ của mình lên phiên bản mới nhất.<animated-vector> yêu cầu cấp API 21 (min hiện tại là 15)

Nhưng Android Studio vẫn cho tôi cảnh báo: hoạt ảnh-vector yêu cầu cấp API 21 (min hiện tại là 15).

tôi đã làm các nội dung sau:

tôi đã thêm các mã sau đây để build.gradle:

defaultConfig { 
    generatedDensities = [] 

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

Bây giờ tập tin build.gradle của tôi trông như thế này:

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' 

} 

hoạt hình của tôi drawable:

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

Trên dòng đầu tiên của hoạt hình drawable, nó nói: hoạt hình-vector yêu cầu cấp API 21 (min hiện tại là 15).

Vậy có gì sai?

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

Mã có chạy không? Tôi nhận thấy rằng có một cảnh báo được đưa ra khi sử dụng ứng dụng mới: thuộc tính srcCompat trong xml. Tuy nhiên nó chỉ là một kiểm tra lint không và mã chạy. Họ có thể sẽ sửa chữa nó trong bản phát hành studio tiếp theo. – Jahnold

+0

Alex đã trả lời. Có, vẫn tồn tại cảnh báo khi sử dụng: app: srcCompat, có vẻ như chúng ta phải bỏ qua cảnh báo và đợi bản cập nhật cho studio. – SMahdiS

Trả lời

9

Ok. Tôi đã thử nghiệm điều này. CNTT HOẠT ĐỘNG! tôi tạo ra hoạt hình drawable vector và bổ sung này vào bố cục:

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

Và đây vào mã:

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

Android studio cho tôi drawable này trong preview nhưng ứng dụng rơi vào start (Android 4.0 điện thoại)

Sau đó, tôi thay thế android:src bởi app:srcCompat và xem trước bị hỏng. Nhưng ứng dụng này đã bắt đầu trên điện thoại và hoạt ảnh trên Android 4.0.

Kết luận: thư viện hỗ trợ hoạt động. Android studio (1.5.1) chưa sẵn sàng.

+1

Bạn đã lưu trữ vectơ của mình vào thư mục nào? drawable-v21 hoặc chỉ có thể vẽ được? – Codeversed

+1

Tôi đặt chúng để vẽ được –

Các vấn đề liên quan