Hencoder学习笔记1-1

HenCoder Android 开发进阶: 自定义 View 1-1 绘制基础

视频重点

  • 自定义绘制的方式是重写绘制方法,其中最常用的是 onDraw()
  • 绘制的关键是 Canvas 的使用
    • Canvas 的绘制类方法: drawXXX() (关键参数:Paint)
    • Canvas 的辅助类方法:范围裁切和几何变换
  • 可以使用不同的绘制方法来控制遮盖关系

自定义绘制知识的四个级别

  • Canvas 的 drawXXX() 系列方法及 Paint 最常见的使用
  • Paint 的完全攻略
  • Canvas 对绘制的辅助——范围裁切和几何变换。
  • 使用不同的绘制方法来控制绘制顺序

draw系列

画颜色

  • canvas.drawColor(Color.parse("#88880000")
  • canvas.drawRGB(100, 200, 100);
  • canvas.drawARGB(100, 100, 200, 100);

画圆

  • canvas.drawCircle(300, 300, 200, paint);

画矩形

  • canvas.drawRect(float left, float top, float right, float bottom, Paint paint) 画矩形
  • canvas.drawRect(RectF rect, Paint paint)
  • canvas.drawRect(Rect rect, Paint paint)

画点

  • cavas.drawPoint(float x, float y, Paint paint)
  • cavas.drawPoints(float[] pts, int offset, int count, Paint paint)
  • cavas.drawPoints(float[] pts, Paint paint) 画点(批量)

画椭圆

  • cavas.drawOval(float left, float top, float right, float bottom, Paint paint)
  • cavas.drawOval(RectF rect, Paint paint)

画线

  • cavas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
  • cavas.drawLines(float[] pts, int offset, int count, Paint paint)
  • cavas.drawLines(float[] pts, Paint paint) 画线(批量)

画圆角矩形

  • cavas.drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)
  • cavas.drawRoundRect(RectF rect, float rx, float ry, Paint paint)

画弧形或扇形

  • cavas.drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, Paint paint)

画自定义图形

  • cavas.drawPath(Path path, Paint paint)

画bitmap

  • drawBitmap(Bitmap bitmap, float left, float top, Paint paint)
  • drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
  • drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
  • drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)
  • drawBitmapMesh()

画文字

  • drawText(String text, float x, float y, Paint paint)

Path

  • Path 方法第一类:直接描述路径
    • 第一组: addXxx() ——添加子图形
      addCircle(float x, float y, float radius, Direction dir) 添加圆
      addOval(float left, float top, float right, float bottom, Direction dir)
      addOval(RectF oval, Direction dir)
      addRect(float left, float top, float right, float bottom, Direction dir)
      addRect(RectF rect, Direction dir)
      addRoundRect(RectF rect, float rx, float ry, Direction dir)
      addRoundRect(float left, float top, float right, float bottom, float rx, float ry, Direction dir)
      addRoundRect(RectF rect, float[] radii, Direction dir)
      addRoundRect(float left, float top, float right, float bottom, float[] radii, Direction dir)
      addPath(Path path)
    • 第二组:xxxTo() ——画线(直线或曲线)
      lineTo(float x, float y)
      rLineTo(float x, float y)
      quadTo(float x1, float y1, float x2, float y2)
      rQuadTo(float dx1, float dy1, float dx2, float dy2)
      cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
      rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
      moveTo(float x, float y)
      rMoveTo(float x, float y)
      arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)
      arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean forceMoveTo)
      arcTo(RectF oval, float startAngle, float sweepAngle)
      addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)
      addArc(RectF oval, float startAngle, float sweepAngle)
      close()
  • Path 方法第二类:辅助的设置或计算
    Path.setFillType(Path.FillType ft)

paint系列

  • Paint.setColor(int color)
  • Paint.setStyle(Paint.Style style)
    • FILL 是填充模式(默认),
    • STROKE 是画线模式(即勾边模式),
    • FILL_AND_STROKE 是两种模式一并使用
  • Paint.setStrokeWidth(float width)
  • Paint.setAntiAlias(boolean aa)
  • paint.setStrokeCap(cap)端点形状
  • Paint.setTextSize(float textSize)

你可能感兴趣的:(Hencoder学习笔记1-1)