android Path里面的各种PathEffect
来源:互联网 发布:查理一世 知乎 编辑:程序博客网 时间:2024/06/08 00:46
首先上图...
MyView.java
public class PathView2 extends View { private int itemHeight; int ROW_GAP=10; int POINT_NUM=20; int[] pointX=new int[POINT_NUM]; int[] pointY=new int[POINT_NUM]; int[] colors=new int[7]; PathEffect[] pathEffects={null,new CornerPathEffect(132),new DiscretePathEffect(2f,5f), new DashPathEffect(new float[]{11,13,22,15,14},10f),null,null,null}; String[] titles={"null","CornerPathEffect","DiscretePathEffect","DashPathEffect","PathDashPathEffect","SumPathEffect","ComposePathEffect"}; int TEXTSIZE=25; int TEXT_HEIGHT=33; float curPercent=0f; int duration=400; float speed=1f/(200*duration/1000); public PathView2(Context context, AttributeSet attrs) { super(context, attrs); ROW_GAP=Utils.dp2px(context,ROW_GAP); itemHeight= (int) ((Utils.getScreenHeight(context)-7*ROW_GAP-7*TEXT_HEIGHT)/7.5); int pointGap=Utils.getScreenWidth(context)/POINT_NUM; // pointX[0]=pointY[0]=0; for (int i=1;i<POINT_NUM;i++){ pointX[i]=i*pointGap; pointY[i]= (int) (Math.random()*itemHeight); } for (int i=0;i<7;i++){ colors[i]= (int) (Math.random()*0xffffffff); //no transparent color colors[i]|=0xff000000; } Path p=new Path(); p.addRect(0,0,11,11, Path.Direction.CCW); pathEffects[4]=new PathDashPathEffect(p,12,12, PathDashPathEffect.Style.ROTATE); pathEffects[5]=new SumPathEffect(pathEffects[4],pathEffects[1]); pathEffects[6]=new ComposePathEffect(pathEffects[2],pathEffects[3]); //set timer final Timer timer=new Timer(); timer.schedule(new TimerTask() { @Override public void run() { curPercent+=speed; if (curPercent>=1f){ curPercent=1f; timer.cancel(); } postInvalidate(); } },10,16); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height= Utils.getScreenHeight(getContext()); int width=Utils.getScreenWidth(getContext()); RelativeLayout.LayoutParams layoutParams= (RelativeLayout.LayoutParams) getLayoutParams(); setMeasuredDimension(width-layoutParams.leftMargin-layoutParams.rightMargin, height-layoutParams.topMargin-layoutParams.bottomMargin); } @Override protected void onDraw(Canvas canvas) { //set paint Paint paint=new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(TEXTSIZE); //set path Path path=new Path(); path.moveTo(0, 0); for (int i=1;i<POINT_NUM;i++){ path.lineTo(pointX[i],pointY[i]*curPercent); } for (int i=0;i<pathEffects.length;i++){ canvas.drawText(titles[i], 0, TEXT_HEIGHT / 2, paint); canvas.translate(0, TEXT_HEIGHT); paint.setColor(colors[i]); paint.setPathEffect(pathEffects[i]); canvas.drawPath(path, paint); canvas.translate(0, itemHeight + ROW_GAP); paint.setPathEffect(null); paint.setColor(0xff000000); } }}
无聊就加了点动画效果......
谢谢!
0 0
- android Path里面的各种PathEffect
- Android里PathEffect的使用
- Android里PathEffect的使用
- Android中PathEffect的使用
- android PathEffect
- Android里面的各种广播
- Android里面的各种广播
- PathEffect的应用:android 绘制虚线效果
- Android 关于PathEffect的使用方法CornerPathEffect
- Android里面各种控件的状态选择器
- android 用Path 绘制各种图形,Path的方法解析
- android 用Path 绘制各种图形,Path的方法解析
- android PathEffect 实例
- Android绘图之PathEffect
- Android PathEffect 效果使用
- Android自定义View【实战教程】3⃣️----Paint类、Path类以及PathEffect类详解
- PathEffect,使用mPaint.setPathEffect为path路径设置不同的效果
- PathEffect类的学习
- 黑马程序员-----Java基础-----Java关键字、抽象类、方法重载、封装
- hibernate注解创建表总是失败,显示表不存在
- ADO.NET之初步了解
- android:preference保存数据(适合于保存上一次用户名与密码)
- [刷题]Merge k Sorted Lists
- android Path里面的各种PathEffect
- android 三个物理按键之按键 返回 函数
- Java的垃圾回收机制(未完)
- 第十三周项目1-动物这样叫
- Android应用开发:网络工具——Volley(一)
- WCF医院管理系统技术解析(五)体检登记(四)
- c++大数模板
- hdu 5249 树状数组求第K大
- PHP配置文件详解php.ini