学习笔记(自定义虚线样式)---PathEffect
来源:互联网 发布:淄博恒久网络 编辑:程序博客网 时间:2024/06/04 20:52
PathEffect有6个子类,想看更多内容,详见:
http://blog.csdn.net/aigestudio/article/details/41447349
之前为了自定义绘制虚线,研究了一下DashPathEffect,详见
http://blog.csdn.net/u014620028/article/details/73380396
为了修改自定义虚线的样式,今天学习了一下PathDashPathEffect。这个可以和之前的自定义虚线结合,扩展虚线样式。
效果图:
PathEffectView
package com.chen.demo2;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.DashPathEffect;import android.graphics.Paint;import android.graphics.Path;import android.graphics.Path.Direction;import android.graphics.PathDashPathEffect;import android.util.AttributeSet;import android.view.View;public class PathEffectView extends View { // 画笔对象 //线段类型虚线 private Paint mPaint; private Paint line_paint; // 路径对象 private Path mPath_1; private Path mPath_2; private Path mPath_3; //默认类型虚线 private DashPathEffect dashPathEffect; //圆点类型虚线 private PathDashPathEffect pathDashPathEffect_1; //矩形类型虚线 private PathDashPathEffect pathDashPathEffect_2; public PathEffectView(Context context) { this(context, null); } public PathEffectView(Context context, AttributeSet attrs) { this(context, attrs, -1); } public PathEffectView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { /* * 实例化画笔并设置属性,并打开抗锯齿 */ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(10); mPaint.setColor(Color.BLACK); line_paint = new Paint(); line_paint.setColor(Color.RED); line_paint.setStyle(Paint.Style.STROKE); line_paint.setStrokeWidth(1); //设置虚线路径起始点 mPath_1 = new Path(); //100,100为起点 mPath_1.moveTo(100, 100); //400,100作为终点 mPath_1.lineTo(800, 100); //设置虚线路径起始点 mPath_2 = new Path(); mPath_2.moveTo(100, 300); mPath_2.lineTo(800, 300); //设置虚线路径起始点 mPath_3 = new Path(); mPath_3.moveTo(100, 500); mPath_3.lineTo(800, 500); //普通虚线 dashPathEffect = new DashPathEffect(new float[]{20, 10, 50, 5, 100, 30, 10, 5}, 0); //圆点类型虚线相关 Path path_1 = new Path(); //direction:方向 //CW:顺时针 //CCW:逆时针 path_1.addCircle(0, 0, 10, Direction.CCW); /** * Dash破碎 the drawn绘图 path by stamping冲压、冲击 it with the specified指定 shape. This only * applies适用 to drawings when the paint's style is STROKE or STROKE_AND_FILL. * If the paint's style is FILL, then this effect is ignored忽略. The paint's * strokeWidth does not affect影响 the results. * @param shape The path to stamp标记 along沿着 * @param advance spacing between each stamp of shape * @param phase amount to offset before the first shape is stamped * @param style how to transform改变、变换 the shape at each position as it is stamped * * 最后一个参数: * TRANSLATE:translate the shape to each position * ROTATE:rotate the shape about its center * MORPH:transform each point, and turn lines into curves */ pathDashPathEffect_1 = new PathDashPathEffect(path_1, 50, 0, PathDashPathEffect.Style.ROTATE); //矩形类型虚线相关 Path path_2 = new Path(); path_2.addRect(0, 0, 10, 10, Direction.CCW); pathDashPathEffect_2 = new PathDashPathEffect(path_2, 50, 0, PathDashPathEffect.Style.ROTATE); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mPaint.setPathEffect(dashPathEffect); canvas.drawPath(mPath_1, mPaint); mPaint.setPathEffect(pathDashPathEffect_1); canvas.drawPath(mPath_2, mPaint); mPaint.setPathEffect(pathDashPathEffect_2); canvas.drawPath(mPath_3, mPaint); }}
阅读全文
0 0
- 学习笔记(自定义虚线样式)---PathEffect
- Android 自定义控件学习-PathEffect
- 自定义水平进度条样式:黑色虚线
- PathEffect的应用:android 绘制虚线效果
- PathEffect类的学习
- 自定义虚线
- android中画虚线--.PathEffect类简单认识
- android中画虚线--.PathEffect类简单认识
- android中画虚线--.PathEffect类简单认识
- android中画虚线--.PathEffect类简单认识
- PathEffect
- PathEffect
- PathEffect
- PathEffect
- android开发步步为营之94:使用PathEffect画虚线和虚线框
- 学习笔记:自定义样式(style)与主题(theme)
- 菜菜鸟-Android学习笔记01-RatingBar的自定义样式
- Ext学习笔记——grid表格渲染自定义样式
- 解决android系统进行OTA升级失败时进入recovery界面不能自动重启问题
- 1、halcon+通过高斯查找图片中的线条
- HDU2682 Tree 题解 【最小生成树】【图论】【Kruskal】
- 合理规范使用VSTS代码管理工具 ---之PR与Branch(tag)的使用
- sqlserver 2008 r2 直接下载地址(百度云)
- 学习笔记(自定义虚线样式)---PathEffect
- angularJS自定义过滤器、服务和指令
- HTTP状态码
- android中的AIDL进程间通信
- bachata Timming
- ACE框架简介以及一个基于ACE的C/S服务程序实例
- 《机器学习实战》第五章——Logistic回归
- select
- 完美解决 Could not detect Mac OS X Version from sw_vers output: '10.12.3