Android PathEffect 效果使用
来源:互联网 发布:淘宝联盟怎么微信推广 编辑:程序博客网 时间:2024/06/03 17:20
本文内容摘自《疯狂Android讲义第3版》
Android系统有以下6种PathEffect效果:
- ComposePathEffect
- CornerPathEffect
- DiscretePathEffect
- DiscretePathEffect
- PathDashPathEffect
- SumPathEffect
示例代码
package shortcut.song.com.myapplication;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.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class PathEffectActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_path_effect); setContentView(new MyPathEffect(this)); } class MyPathEffect extends View { float phase; PathEffect[] effects = new PathEffect[7]; int[] colors; private Paint paint; Path path; public MyPathEffect(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 <= 40; i++) { path.lineTo(i * 20, (float)Math.random() * 60); ; } path.close(); 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); 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.MORPH); effects[5] = new ComposePathEffect(effects[2], effects[4]); effects[6] = new SumPathEffect(effects[4], effects[3]); //将画布移动至(8,8)处开始绘制; 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;//改变phase的值,形成动画效果 invalidate(); } }}
程序运行效果图:
阅读全文
0 0
- Android PathEffect 效果使用
- Android Paint 线条效果 PathEffect
- Android里PathEffect的使用
- Android里PathEffect的使用
- Android中PathEffect的使用
- PathEffect的应用:android 绘制虚线效果
- android PathEffect
- Paint---PathEffect(路径效果)
- android PathEffect 实例
- Android绘图之PathEffect
- Android基础入门教程——8.3.12 Paint API之—— PathEffect(路径效果)
- PathEffect,使用mPaint.setPathEffect为path路径设置不同的效果
- PathEffect
- PathEffect
- PathEffect
- PathEffect
- Android Paint之PathEffect详解
- Android 自定义控件学习-PathEffect
- Unable to instantiate application com.yunque.www.yunque.app.YunQuApplication: java.lang.ClassNotFoun
- 前端代码规范
- Integer’s Power HDU
- 一个完整的android项目需要哪些标配
- JAVA第一课第二节知识点
- Android PathEffect 效果使用
- ZJU1037-Gridland
- Spark参数配置
- map集合
- MapReduce读写hbase
- Java设计模式——责任链模式
- WebService之CXF介绍
- ITIL 2011服务管理与认证读书笔记一——IT服务管理与ITIL
- 找朋友