package com.wcs;

import android.R.color;
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.os.Bundle;
import android.view.View;

public class PathTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}

class MyView extends View {

float phase;
PathEffect[] effects = new PathEffect[7];
int[] colors;
private Paint paint;
Path path;

public MyView(Context context) {
super(context);
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4);
path = new Path();
path.moveTo(0, 0);
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) {
canvas.drawColor(Color.WHITE);
effects[0]=null;
effects[1]=new CornerPathEffect(10);
effects[2]=new DiscretePathEffect(3.0f, 5.0f);
effects[3]=new DashPathEffect(new float[]{20,10,5,10}, phase);
Path p=new Path();
p.addRect(0, 0,8,8,Path.Direction.CCW);
effects[4]=new PathDashPathEffect(p, 12, phase,PathDashPathEffect.Style.ROTATE);
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+=1;
invalidate();
}

}
}
}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. MySQL 清除表空间碎片的实例详解
  2. navicat不能创建函数解决方法分享
  3. 使用navicate连接阿里云服务器上的mysql
  4. mysql数据存储过程参数实例详解
  5. MySQL中or语句用法示例
  6. Mysql中explain作用详解
  7. 详解mysql中的冗余和重复索引
  8. MySQL语句加锁的实现分析
  9. mysql 启动1067错误及修改字符集重启之后
  10. MySQL优化总结-查询总条数