赞
踩
记录1:
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
-
- Paint paint = new Paint();
-
- //去锯齿
- paint.setAntiAlias(true);
- //设置眼色
- paint.setColor(Color.BLUE);
- //设置空心
- paint.setStyle(Paint.Style.STROKE);
- //设置边宽
- paint.setStrokeWidth(3);
-
-
- RectF rect = new RectF(0,0, 200, 200);
- canvas.drawRoundRect(rect, 10, 10, paint);
- paint.setColor(Color.RED);
- Path path = new Path();
- // path.arcTo(rect,0, 180,true);
- path.quadTo(200, 200, 200, 200);
- // path.close();
- // path.quadTo(99, 99, 99, 2);
- // path.quadTo(99, 99, 2, 99);
- //图案1:
- // path.moveTo(rect.right/2, rect.top);
- // path.quadTo((rect.right-rect.left)/2, (rect.bottom-rect.top)/2, rect.right, (rect.bottom-rect.top)/2);
- // path.quadTo((rect.right-rect.left)/2, (rect.bottom-rect.top)/2, (rect.right-rect.left)/2, rect.bottom);
- // path.quadTo((rect.right-rect.left)/2, (rect.bottom-rect.top)/2, rect.left, (rect.bottom-rect.top)/2);
- // path.quadTo((rect.right-rect.left)/2, (rect.bottom-rect.top)/2, rect.right/2, rect.top);
- // path.lineTo(rect.right, (rect.bottom-rect.top)/2);
- // path.lineTo((rect.right-rect.left)/2, rect.bottom);
- // path.lineTo(rect.left, (rect.bottom-rect.top)/2);
- // path.lineTo(rect.right/2, rect.top);
- //----------------------------------------------------------
-
- //图案2:波浪线
- // path.moveTo(0, rect.bottom/2);
- // path.quadTo(rect.right/4, rect.bottom, rect.right/2, rect.bottom/2);
- // path.quadTo(rect.right/4*3, rect.top, rect.right, rect.bottom/2);
-
- //图案3: 梯形
- // path.moveTo(rect.right/2,rect.top);
- // path.lineTo(rect.right/2, rect.bottom);
- // path.lineTo(rect.left,rect.bottom/6*4);
- // path.lineTo(rect.left,rect.bottom/6*2);
- // path.lineTo(rect.right/2,rect.top);
-
-
-
- canvas.drawPath(path, paint);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
-
- Paint paint = new Paint();
-
- //去锯齿
- paint.setAntiAlias(true);
- //设置眼色
- paint.setColor(Color.BLUE);
- //设置空心
- paint.setStyle(Paint.Style.STROKE);
- //设置边宽
- paint.setStrokeWidth(3);
-
-
- RectF rect = new RectF(0,0, 200, 200);
- canvas.drawRoundRect(rect, 10, 10, paint);
- paint.setColor(Color.RED);
- Path path = new Path();
-
-
- path.moveTo(rect.width(), rect.height() / 2);
- paint.setColor(Color.YELLOW);
- canvas.drawPath(path, paint);
- path.lineTo((float) (rect.width() * 0.75), (float) (rect.width() / 2 - rect.width() * Math.sqrt(3) / 4));
- paint.setColor(Color.BLUE);
- canvas.drawPath(path, paint);
- path.lineTo((float) (rect.width() * 0.25), (float) (rect.width() / 2 - rect.width() * Math.sqrt(3) / 4));
- path.lineTo(0, rect.width() / 2);
- paint.setColor(Color.BLACK);
- canvas.drawPath(path, paint);
- path.lineTo((float) (rect.width() * 0.25), (float) (rect.width() / 2 + rect.width() * Math.sqrt(3) / 4));
- path.lineTo((float) (rect.width() * 0.75), (float) (rect.width() / 2 + rect.width() * Math.sqrt(3) / 4));
- path.lineTo(rect.width(), rect.height() / 2);
-
- canvas.drawPath(path, paint);
-
-
- canvas.drawPath(path, paint);
-
-
- }
记录3:
-
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
-
- //把整张画布绘制成白色
- canvas.drawColor(Color.WHITE);
- Paint paint = new Paint();
-
- //去锯齿
- paint.setAntiAlias(true);
- //设置颜色
- paint.setColor(Color.BLUE);
-
- //---------------画空心图形--------------------
- //设置空心
- paint.setStyle(Paint.Style.STROKE);
- //设置边宽
- paint.setStrokeWidth(3);
-
- //绘制圆形
- canvas.drawCircle(40, 40, 30, paint);
- //绘制正方形
- canvas.drawRect(10, 80, 70, 140, paint);
- //绘制矩形
- canvas.drawRect(10, 150, 70, 190, paint);
-
- //绘制圆角矩形
- RectF re2 = new RectF(10,200,70,230);
- canvas.drawRoundRect(re2, 15, 15, paint);
- //绘制椭圆
- RectF rel = new RectF(10,240,70,270);
- canvas.drawOval(rel, paint);
- //定义一个Path对象,封闭一个三角形
- Path path1 = new Path();
- path1.moveTo(10, 340);
- path1.lineTo(70, 340);
- path1.lineTo(40, 290);
- path1.close();
- //根据Path进行绘制,绘制三角形
- canvas.drawPath(path1, paint);
-
- //定义一个Path对象,封闭一个五角星
- Path path2 = new Path();
- path2.moveTo(27, 360);
- path2.lineTo(54, 360);
- path2.lineTo(70, 392);
- path2.lineTo(40, 420);
- path2.lineTo(10, 392);
- path2.close();
- //根据Path进行绘制,绘制五角星
- canvas.drawPath(path2, paint);
-
- //--------------画实心图形---------------------------------
- //设置填丛风格后进行绘制
- //实心
- paint.setStyle(Paint.Style.FILL);
- paint.setColor(Color.RED);
- canvas.drawCircle(120, 40, 30, paint);
- //绘制正方形
- canvas.drawRect(90, 80, 150, 140, paint);
- //绘制矩形
- canvas.drawRect(90, 150, 150, 190, paint);
-
- //绘制圆角矩形
- RectF re22 = new RectF(90,200,150,230);
- canvas.drawRoundRect(re22, 15, 15, paint);
- //绘制椭圆
- RectF re21 = new RectF(90, 240, 150, 270);
- canvas.drawOval(re21, paint);
-
- Path path3 = new Path();
- path3.moveTo(90, 340);
- path3.lineTo(150, 340);
- path3.lineTo(120, 290);
- path3.close();
- //绘制三角形
- canvas.drawPath(path3,paint);
-
- //绘制五角形
- Path path4 = new Path();
- path4.moveTo(106, 360);
- path4.lineTo(134, 360);
- path4.lineTo(150, 392);
- path4.lineTo(120, 420);
- path4.lineTo(90, 392);
- path4.close();
- canvas.drawPath(path4, paint);
-
- //--------------渐变图形------------------------------
- //设置渐变器后绘制
- //为Paint设置渐变器
- Shader mShasder = new LinearGradient(0, 0, 40, 60, new int[]{Color.RED,Color.GREEN,Color.BLUE,Color.YELLOW}, null, Shader.TileMode.REPEAT);
- paint.setShader(mShasder);
- //设置阴影
- paint.setShadowLayer(45, 10, 10, Color.GRAY);
- //绘制圆形
- canvas.drawCircle(200, 40, 30, paint);
- //绘制正方形
- canvas.drawRect(170, 80, 230, 140, paint);
- //绘制矩形
- canvas.drawRect(170, 150, 230, 190, paint);
-
- //绘制圆角的矩形
- RectF re31 = new RectF();
- canvas.drawRoundRect(re31, 15, 15, paint);
-
- //绘制椭圆
- RectF re32 =new RectF();
- canvas.drawOval(re32, paint);
-
- //根据Path,绘制三角形
- Path path5 = new Path();
- path5.moveTo(170, 340);
- path5.lineTo(230, 340);
- path5.lineTo(200, 290);
- path5.close();
- canvas.drawPath(path5, paint);
-
- //根据PAth,进行绘制五角形
- Path path6 = new Path();
- path6.moveTo(186, 360);
- path6.lineTo(214, 360);
- path6.lineTo(230, 392);
- path6.lineTo(200, 420);
- path6.lineTo(170, 392);
- path6.close();
- canvas.drawPath(path6, paint);
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。