【开源】AnimatedPathView

AnimatedPathView

  •  https://github.com/matthewrkula/AnimatedPathView

    介绍:

    根据设置的path路径绘制图形的自定义view。结合属性动画就可以实现路径动画效果。AnimatedPathView的原理是用了DashPathEffect,DashPathEffect能将离散的点形成的路径模拟成连续的线条,这是一个非常有用的类。

    运行效果:

  •  

    使用说明:

    关于path的使用请看这篇文章 Android画图之Path类的使用 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    package com.mattkula.animatedpathview.sample;
     
    import android.animation.ObjectAnimator;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewTreeObserver;
    import android.view.animation.LinearInterpolator;
    import com.mattkula.animatedpathview.library.AnimatedPathView;
     
    public class MyActivity extends Activity {
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
            final AnimatedPathView view = (AnimatedPathView)findViewById(R.id.animated_path);
     
            ViewTreeObserver observer = view.getViewTreeObserver();
            if(observer != null){
                observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
     
                        float[][] points = new float[][]{
                                {0, 0},
                                {view.getWidth(), 0},
                                {view.getWidth(), view.getHeight()},
                                {0, view.getHeight()},
                                {0, 0},
                                {view.getWidth(), view.getHeight()},
                                {view.getWidth(), 0},
                                {0, view.getHeight()}
                        };
                        view.setPath(points);
                    }
                });
            }
     
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ObjectAnimator anim = ObjectAnimator.ofFloat(view, "percentage", 0.0f, 1.0f);
                    anim.setDuration(2000);
                    anim.setInterpolator(new LinearInterpolator());
                    anim.start();
                }
            });
        }
    }


    xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
            >
     
        <com.mattkula.animatedpathview.library.AnimatedPathView
                android:id="@+id/animated_path"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:strokeColor="@android:color/holo_red_light"
                app:strokeWidth="10"/>
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="Press top half of screen"
                />
    </LinearLayout>

     

    相关代码

    • SearchAnimation

posted on 2015-04-09 09:15  wasdchenhao  阅读(143)  评论(0)    收藏  举报

导航