【开源】AnimatedPathView
AnimatedPathView
- https://github.com/matthewrkula/AnimatedPathView
介绍:
根据设置的path路径绘制图形的自定义view。结合属性动画就可以实现路径动画效果。AnimatedPathView的原理是用了DashPathEffect,DashPathEffect能将离散的点形成的路径模拟成连续的线条,这是一个非常有用的类。运行效果:
![]()
-
使用说明:
关于path的使用请看这篇文章 Android画图之Path类的使用
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152package 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 {@Overridepublic 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(newViewTreeObserver.OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {view.getViewTreeObserver().removeGlobalOnLayoutListener(this);float[][] points =newfloat[][]{{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(newView.OnClickListener() {@Overridepublic void onClick(View view) {ObjectAnimator anim = ObjectAnimator.ofFloat(view,"percentage", 0.0f, 1.0f);anim.setDuration(2000);anim.setInterpolator(newLinearInterpolator());anim.start();}});}}
xml12345678910111213141516171819202122<?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.AnimatedPathViewandroid: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"/><TextViewandroid:layout_width="fill_parent"android:layout_height="0dp"android:layout_weight="1"android:text="Press top half of screen"/></LinearLayout>
posted on 2015-04-09 09:15 wasdchenhao 阅读(143) 评论(0) 收藏 举报

浙公网安备 33010602011771号