Path
是什么
Path即路径,通过canvas的drawPath(path,paint)方法,按照指定的路径去绘制。
怎么样
Android中还为路径绘制提供了PathEffect的来指定绘制的效果,PathEffect包含了几个子类DashPathEffect,ComposePathEffect,SumPathEffect,CornerPathEffect,DiscretePathEffect,PathDashPathEffect。Path还有Path.op方法用于对两个Path对象做相应的运算组合(combine),具体的说是根据不同的op参数及path2参数来影响path1对象,有点类似于数学上的集合运算…….
怎么用
PathEffect
pathEffect几个子类的效果很难描述,用demo表示,看运行效果
其中有虚线的是有动画的,看着眼花缭乱,最明显的就是虚线和实线的区别,那两条实线没看出有什么区别,其余的虚线,也大同小异。
代码演示
新建项目,创建MyPathView类继承View重写三个构造方法
在构造方法中初始化画笔
package com.cd.pathdemo;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposePathEffect;
import android.graphics.CornerPathEffect;
import android.graphics.DashPathEffect;
import android.graphics.DiscretePathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathDashPathEffect;
import android.graphics.PathEffect;
import android.graphics.SumPathEffect;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by Sky
* on 2016/10/30.
* Describe:
*/
public class MyPathView extends View {
int[] colors;
Paint mPaint;
float phase;
Path path;
PathEffect[] patheffect = new PathEffect[7];
public MyPathView(Context context) {
super(context);
init();
}
public MyPathView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyPathView(Context context, Attri