2012-02-02 37 views
25

Tôi đang viết một ứng dụng Android và tôi muốn phát một hoạt ảnh SVG đơn giản. Tôi biết rằng Android không cung cấp hỗ trợ SVG; lựa chọn của tôi là gì đây?Android và phát hoạt ảnh SVG

+0

Tôi cũng quan tâm đến điều này. –

+0

http://blog.sqisland.com/2014/10/first-look-at-animated-vector-drawable.html –

Trả lời

3
  1. Hãy hình ảnh SVG của bạn và chuyển nó sang một VectorDrawable here
  2. Thêm tập tin XML đã download của bạn để dự án của bạn và xem nó trông như thế. Heres một ví dụ về một VectorDrawable chuẩn bị cho một vòng quay và đường dẫn morph hình ảnh động:

    <vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:height="64dp" 
    android:width="64dp" 
    android:viewportHeight="600" 
    android:viewportWidth="600" > 
    <group 
        android:name="rotationGroup" 
        android:pivotX="300.0" 
        android:pivotY="300.0" 
        android:rotation="45.0" > 
        <path 
         android:name="v" 
         android:fillColor="#000000" 
         android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" /> 
    </group> 
    

3 Bây giờ, tạo một AnimatedVectorDrawable nơi bạn tham khảo các rotationGroup và đường dẫn morph trong tạo VectorDrawable

<?xml version="1.0" encoding="UTF-8"?> 
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/vectordrawable"> 
    <target android:name="rotationGroup" android:animation="@anim/rotation" /> 
    <target android:name="v" android:animation="@anim/path_morph" /> 
</animated-vector> 

4 Tạo hai hoạt ảnh cho AnimatedVectorDrawable:

<objectAnimator 
    android:duration="6000" 
    android:propertyName="rotation" 
    android:valueFrom="0" 
    android:valueTo="360" /> 

và:

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <objectAnimator 
     android:duration="3000" 
     android:propertyName="pathData" 
     android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z" 
     android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z" 
     android:valueType="pathType"/> 
</set> 

(Cũng có thể để xác định tất cả điều này trong một tập tin, hãy tham khảo docs here)

Một cách để sau đó bắt đầu các hình ảnh động là do nhận được drawable từ quan điểm và chạy start().

+0

Có bài học nào về cách chúng ta có thể hiểu được đường dẫn svg không? Và giá trị của nó? – RoCk