android绘图Path类仿加速球水面波动效果

android提供的Path类,他可以预先在View上连成路径,然后调用Canvas的drawPath(path,paint),,沿着路径画出来即可; 【1】画三角形

//path.moveTo(100, 100);//path.lineTo(0, 200);//path.lineTo(200, 200);//path.close();//连接首尾//canvas.drawPath(path, paint);//canvas.drawTextOnPath(“我沿着这条线走”, path, 0, 0, paint);

【画贝塞尔曲线】

【仿水边波动效果】

{private Paint paint;private Path path;private Paint paintPoint;private int width;private int height;private int count = 0;private int size = 0;private boolean isAdd=true;private Handler handler = new Handler() {(Message msg) {super.handleMessage(msg);switch (msg.what){case 0x23:count+=5;if(count>=80){count=0;}if (isAdd){size++;if(size>10){isAdd = false;}}else{size–;if(size<=-10){isAdd =true;}}invalidate();sendEmptyMessageDelayed(0x23,100);break;}}};public MyPathView(Context context, AttributeSet attrs) {super(context, attrs);paint = new Paint();paint.setAntiAlias(true);paint.setTextSize(30);paint.setStyle(Paint.Style.STROKE);paintPoint = new Paint();paintPoint.setStrokeWidth(10);paintPoint.setColor(Color.GREEN);paintPoint.setStyle(Paint.Style.FILL);path = new Path();handler.sendEmptyMessageDelayed(0x23, 1000);}(Canvas canvas) {super.onDraw(canvas);path.reset();path.moveTo(count, 100);for (int i = 0; i < 10; i++) {path.rQuadTo(20, 20, 40, 0);path.rQuadTo(20, -20, 40, 0);}canvas.drawPath(path, paint);canvas.drawRect(200, 0, 400, 200, paint);}(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);setMeasuredDimension(width, height);}}

布局

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”android:orientation=”vertical” android:layout_width=”match_parent”android:layout_height=”match_parent”><android:layout_width=”match_parent”android:layout_height=”match_parent” /></LinearLayout>

把艰辛的劳作看作是生命的必然,

android绘图Path类仿加速球水面波动效果

相关文章:

你感兴趣的文章:

标签云: