为什么80%的码农都做不了架构师?>>>   

translate作用就是移动原点,默认的原点(0,0)是在屏幕左上角的,你可以通过translate(x,y)把点(x,y)作为原点。即,translate(float x,float y)函数是将整个canvas水平移动x,垂直移动y距离。

下面有一段很详细的解释:

Translate - Basically do what it says. Just translate the canvas using x,y. If you want to draw two objects and the one is just translation of the other e.g x2 = x1 + 50 for each point . You don't have to make all your calculations again for the second object but you can just translate the canvas and draw again the same object.

Ok,image you have a canvas and you want to draw 2 trees on it and one bird which is above the first tree. The trees have the same y coordinate but different x (let's say for example 50 inches). So what are you going to do ?

You'll draw the first three then you'll move your canvas 50 inches to the right ( which is what canvas.translate do ) and will draw the second tree. In order to restore the original position of the canvas you'll move it again 50 inches but this time to the left. And now when you draw the bird it'll be above the first tree, if you don't restore the canvas original state all object that you draw after the translation will be translated to - in our example the bird will be drawn above the second tree

From:What does canvas.translate do?
Link:http://stackoverflow.com/questions/5789813/what-does-canvas-translate-do

转载于:https://my.oschina.net/jerikc/blog/122329

Android canvas.translate相关推荐

  1. Android Canvas rotate 和translate 两个方法的研究

    转自:http://www.verydemo.com/demo_c131_i3507.html 首先我们来看这样一个需求:显示一个竖向显示的TextView.说白了,就是把我们日常使用的TextVie ...

  2. android 画布控件,Android canvas画图操作之切割画布实现方法(clipRect)

    本文实例讲述了Android canvas画图操作之切割画布实现方法.分享给大家供大家参考,具体如下: android切割画布的历程不算很难,可是理解起来也比较麻烦,这里写一下我的理解 但是不一定正确 ...

  3. Android Canvas drawText实现中文垂直居中

    目标: 把中文字符绘制到目标矩形的居中位置. 问题: Android的Canvas绘图,drawText里的origin是以baseline为基准的,直接以目标矩形的bottom传进drawText, ...

  4. Android canvas

    1.Canvas Canvas指画布,表现在屏幕上就是一块区域,可以在上面使用各种API绘制想要的东西. canvas内部维持了一个mutable Bitmap,所以它可以使用颜色值去填充整个Bitm ...

  5. Android Canvas 平移、缩放、旋转的理解

    自己对这个几个方法,用了好多次了,但对它们的原理概念都还是没仔细理解清楚,真是太菜了. View和canvas并不是同一个东西,可以这样想象,我们的View是固定的,相当于与一个画板或者画框,画板范围 ...

  6. Android Canvas类

    1. Canvas类 Canvas主要用于2D绘图,它提供了很多相应的drawXxx()方法,Canvas的获取方式有三种 重写View的onDraw(Canvas)方法 @Override prot ...

  7. Android Canvas Layers

    Canvas 在一般的情况下可以看作是一张画布,所有的绘图操作如drawBitmap, drawCircle都发生在这张画布上,这张画板还定义了一些属性比如Matrix,颜色等等. 但是如果需要实现一 ...

  8. Canvas translate,scale,rotate

    下面使用三个小例子作为讲解: 1.translate:将canvas默认的原点(0,0),进行移动 import android.content.Context; import android.gra ...

  9. Android Canvas绘图

    以图形处理来说,我们最常用到的就是在一个View上画一些图片.形状或者自定义的文本内容,这里我们都是使用Canvas来实现的.你可以获取View中的Canvas对象,绘制一些自定义形状,然后调用Vie ...

最新文章

  1. 高考计算机算分么,高考分数是怎么算出来的
  2. linus启动mysql失败_Linux下MySQL启动失败的解决一例
  3. oc---类方法load和initialize的区别
  4. HTTP协议入门——1.1版本
  5. Win32Asm学习笔记[不断更新]
  6. 几种实用的pythonic语法
  7. 社区列表根据关注人数排序(排行榜)的实现思路整理
  8. html 星星字体,做华丽的星星文字效
  9. 激光打印机无线服务器,插上无线翅膀 兄弟1218W激光打印机评测
  10. Vue项目中生成二维码
  11. 我的团长我的团第八集
  12. linux超线程问题
  13. 局域网内两台电脑无法共享文件问题
  14. [深度学习论文笔记]UCTransNet:从transformer的通道角度重新思考U-Net中的跳跃连接
  15. SpringCloud升级之路2020.0.x版-42.SpringCloudGateway 现有的可供分析的请求日志以及缺陷
  16. 使用jsonp跨域调用百度js实现搜索框智能提示,并实现鼠标和键盘对弹出框里候选词的操作【附源码和在线测试地址】
  17. python 发送匿名邮件或无发件人
  18. MySQL实现字符串分割split并获取长度
  19. Asp.Net初学小结
  20. 一人一机一密码:锐捷灵活办公为鲁嘉涂料配备“Wi-Fi安全钥匙”

热门文章

  1. 阿里云云服务器安装jdk、mysql
  2. 微软可能是全球最大的开源贡献者,但开发者似乎并不买账​​​​​​​
  3. React基础——快速搭建开发环境
  4. 共谋大数据产业发展新篇章
  5. Knockout应用开发指南(完整版) 目录索引
  6. 如何去除My97 DatePicker控件上右键弹出官网的链接 - 如何debug混淆过的代码
  7. 通用社区登陆组件技术分享(开源)下篇:OAuth 源码下载及原理解说
  8. BCE或能成为BCH的一个侧链
  9. リストに項番をつける
  10. java消息服务,JMS 和 ActiveMQ