Path类
来源:互联网 发布:黑科技网络验证管理端 编辑:程序博客网 时间:2024/05/22 01:38
实例
MainActivity.java
package com.example.pathtest;
import android.os.Bundle;
import android.app.Activity;
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.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(MainActivity.this));
}
class MyView extends View{
PathEffect[] effects=new PathEffect[7];
float phase=0;
Paint paint;
int colors[];
Path path;
public MyView(Context context) {
super(context);
paint=new Paint();
//空心
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4);
//创建并初始化Path
path=new Path();
path.moveTo(0, 0);
//随机生成15个点
for(int i=1;i<=15;i++){
path.lineTo(i*20, (float) (Math.random()*60));
}
//初始化七个颜色
colors=new int[]{
Color.BLACK,Color.BLUE,Color.CYAN,Color.GREEN,Color.MAGENTA,Color.RED,Color.YELLOW
};
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//将背景填充为白色
canvas.drawColor(Color.WHITE);
//初始化7种路径效果
//不使用路径效果
effects[0]=null;
//使用CornerPathEffect路径效果
effects[1]=new CornerPathEffect(5);
//使用DiscretePathEffect
effects[2]=new DiscretePathEffect(3.0f, 5.0f);
//使用DashPathEffect
effects[3]=new DashPathEffect(new float[]{10,5,5,5}, phase);
//使用PathDashPathEffect
Path p=new Path();
//CCW表示逆时针
p.addRect(0, 0, 8, 8, Path.Direction.CCW);
effects[4]=new PathDashPathEffect(p, 5, phase, PathDashPathEffect.Style.MORPH);
effects[5]=new ComposePathEffect(effects[2], effects[4]);
effects[6]=new SumPathEffect(effects[4], effects[3]);
canvas.translate(8, 8);
for(int i=0;i<effects.length;i++){
paint.setPathEffect(effects[i]);
paint.setColor(colors[i]);
canvas.drawPath(path, paint);
canvas.translate(0, 60);
}
//改变phase实现动画效果
phase+=1;
invalidate();
}
}
}
- Path类
- Path类
- Path类
- <Path>类
- path类
- 深入path类
- 说一下Path类
- Path 类入门实例
- 利用Path类绘图
- Android之Path类
- Path类API详解
- android中的path类
- System.IO.Path类
- path帮助类
- Android之Path类
- Path静态类
- paint类,path用法
- System.IO.Path类
- 给开发者提供的 35 款 JavaScript 图形图表库
- MergeSort 求逆序数
- linux考题
- [VS]_[Visual Studio的专业版旗舰版和express之间的区别]
- Linux内核调试:kdump、vmcore、crash、kernel-debuginfo
- Path类
- JSON数据
- 开发笔记之20140224
- 【Android New Features】—— 关于ADT 17的BuildConfig.DEBUG
- svn revert整个目录
- hdu 3336 Count the string KMP+DP
- ArcEngine WGS84坐标与Beijing54坐标的相互转换
- SQL 数据分组
- 序列化和反序列化,异步调用web/wcf/函数