当前位置: 首页 > news >正文

android drawline参数,Android绘图具体应用方式总结

在Android操作系统中,有很多功能技巧可以帮助我们轻松的实现一些需求。比如对图像图像的处理等等。我们在这里就会为大家带来一些有关Android绘图的方法,希望能是朋友们充分掌握这方面的应用。

绘制各种图形、文字使用Canvas类中drawRect、drawText等方法,详细函数列表以及参数说明可以查看sdk

图形的样式由paint参数控制

Paint类也有很多参数设置方法

坐标由Rect和RectF类管理

通过Canvas、Paint和Rect 就可以绘制游戏中需要的大多数基本图形了

Android绘图中需要注意的一些细节

绘制实心矩形,需要设置paint属性:paint.setStyle(Style.FILL); 通过Style的几个枚举值改变绘制样式

以下写的有点乱,随时添加一些记录点, 以后再整理啦~~~~~

1. Rect对象

一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域,即是说使用 Rect.contains(left, top)为true, Rect.contains(right, bottom)为false

2.drawLine方法

drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1

验证方法:

Canvasc=canvas;

paint.setColor(Color.RED);

c.drawLine(x, y, x+c.getWidth()-1, y, paint);

c.drawLine(x, y+height-1, x+c.getWidth(), y+height-1, paint);

paint.setColor(Color.BLUE);

c.drawPoint(x+c.getWidth()-1, y, paint);

说明drawLine是没有绘制到右边最后一个点的

3.drawRect(Rect r, Paint paint)

当绘制空心矩形时,绘制的是一个左闭右闭的区域

验证方法:

rect.set(x, y, x+width, y+height);

paint.setStyle(Style.STROKE);

paint.setColor(Color.BLUE);

c.drawRect(rect, paint);

paint.setColor(Color.RED);

c.drawLine(x, y, x+width, y, paint);

c.drawLine(x, y+height, x+width, y+height, paint);

c.drawLine(x, y, x, y+height, paint);

c.drawLine(x+width, y, x+width, y+height, paint);

当绘制实心矩形时,绘制的是一个左闭右开的区域

验证方法:

rect.set(x, y, x+width, y+height);

paint.setColor(Color.RED);

c.drawLine(x, y, x+width, y, paint);

c.drawLine(x, y+height, x+width, y+height, paint);

c.drawLine(x, y, x, y+height, paint);

c.drawLine(x+width, y, x+width, y+height, paint);

paint.setStyle(Style.FILL);

paint.setColor(Color.BLUE);

c.drawRect(rect, paint);

这个规则跟j2me也是一样的,在j2me里,drawRect长宽会多画出1px。SDK的说明是:

The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width or height is less than zero, nothing is drawn.

例如drawRect(10,10,100,1)绘制,结果是一个2px高的矩形,用fillRect(10,10,100,1),结果是一个1px高的矩形

以上就是对Android绘图的具体介绍。

【责任编辑:曹凯 TEL:(010)68476606】

点赞 0

http://www.lryc.cn/news/567408.html

相关文章:

  • 安装C++语言图形库graphics.h
  • d3.js介绍以及使用d3.js画一个圆圈和柱状图附带讲解d3.js的enter对象、update对象、exit对象
  • zencart经典模板lightinthebox安装教程及修改建议 (转)
  • JB的测试之旅-SEO了解下
  • 《BJBR虚拟仿真解决方案(描述精选)》(Yanlz+SteamVR+5G+AI+VR+AR+MR+HR+BR+CR+DR+ER+FR+GR+人工智能+人机交互+立钻哥哥+==)
  • G2O整理
  • KVM——1——KVM简介及基础安装配置
  • Android SE的多种集成形态:eSE、UICC、SD Card
  • java画环fillArc函数_使用Java的Graphics类进行绘图的方法详解
  • CoInitialize浅析一
  • Bibtex 参考文献样式
  • mysql排序order by asc | desc
  • 怎样把hlp转换成html,如何将HLP文件转换为CHM文件
  • 网卡bonding模式 - bond0、1、4配置
  • Python Web学习笔记,电影网站
  • 深入挖掘Windows脚本技术
  • 大数据流式计算
  • CocosCreator 源码cc.FadeOut详解
  • EMNLP 2022 | ELMER: 高效强大的非自回归预训练文本生成模型
  • Serverlet理解
  • CSS3属性border-radius参数详解
  • Idea Module not specified
  • Cable Modem工作原理
  • front-page.php模板,WordPress主题教程:WordPress的模板层次
  • VLAD原理简介
  • 【笔记】php-Cookie和Session
  • dubbo学习之本地存根实践
  • Admin5论坛营销插件
  • monty python-网易云音乐
  • 程序设计语言有很多种,下面是一些常见的程序设计语言: