技术标签: RectF Android 自定义控件 Rect android 自定义 Android
Rect()
Rect(int left,int top,int right,int bottom)
Rect(Rect r)
public final boolean isEmpty(){
return left>=right ||top>= bottom;
}
判断 Rect 是否为空,也就是矩形区域面积是否为 0 或者为无效矩形。
public final int width(){
return right - left;
}
返回矩形的宽度。
public final int height(){
return bottom - top;
}
返回矩形的高度。
public final int centerX(){
return (left + right) >> 1;
}
计算矩形中心点的 x 坐标,右移一位相当于除以 2,移位运算比普通的除法运算效率
更高。
public final int centerY(){
return (top + bottom) >> 1;
}
计算矩形中心点的 y 坐标。
public final float exactCenterX(){
return (left + right) * 0.5f;
}
计算矩形中心点的 x 坐标,返回 float 类型,结果更精确。
public final float exactCenterY(){
return (top + bottom) * 0.5f;
}
计算矩形中心点的 y 坐标,返回 float 类型,结果更精确。
public void setEmpty(){
left = right = top = bottom = 0;
}
将矩形的 left、top、right 和 bottom 置 0。
public void set(int left,int top,int right,int bottom){
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
给 left、top、right 和 bottom 重新赋值。
public void set(Rect src){
this.left = src.left;
this.top = src.top;
this.right = src.right;
this.bottom = src.bottom;
}
public void offset(int dx,int dy){
left += dx;
top += dy;
right += dx;
bottom += dy;
}
矩形的 left 和 right 同时移动相同的距离 dx,矩形的 top 和 bottom 同时移动相同的距
离 dy,实际上就是将矩形移动(dx、dy)距离,正负决定移动的方向。
public void offsetTo(int newLeft,int newTop){
right += newLeft - left;
bottom += newTop - top;
left = newLeft;
top = newTop;
}
offsetTo()方法也是移位,和 offset()不同的是前者是绝对定位,后者是相对定位。
public void inset(int dx,int dy){
left += dx;
top += dy;
right -= dx;
bottom -= dy;
}
实现了矩形的缩放功能,缩放中心点就是矩形的中心点,要注意的是 dx、dy 为正数时
public boolean contains(int x,int y){
return left < right && top < bottom
&& x >= left && x < right && y >= top && y < bottom;
}
判断点(x,y)是否位于矩形内。
public boolean contains(int left,int top,int right,int bottom){
return this.left < this.right && this.top < this.bottom
&& this.left <= left && this.top <= top
&& this.right >= right && this.bottom >= bottom;
}
判断传递过来的矩形是否位于矩形内。
public boolean contains(Rect r){
return this.left < this.right && this.top < this.bottom
&& left <= r.left && top <= r.top && right >= r.right && bottom >= r.bottom;
}
判断传递过来的矩形是否位于矩形内。
public boolean intersect(int left,int top,int right,int bottom){
if (this.left < right && left < this.right && this.top < bottom && top < this.bottom) {
if (this.left < left) this.left = left;
if (this.top < top) this.top = top;
if (this.right > right) this.right = right;
if (this.bottom > bottom) this.bottom = bottom;
return true;
}
return false;
}
传入 Rect 的 left、top、right、bottom,并将构建的 Rect 对象与当前 Rect 对象做交集运算,结果保存在当前 Rect 对象中。
public boolean intersect(Rect r){
return intersect(r.left, r.top, r.right, r.bottom);
}
传入新的 Rect 对象,并将该对象与当前 Rect 对象做交集运算,结果保存在当前 Rect对象中。比如有下面的代码段:
Rect rect1 = new Rect(0, 0, 400, 400);
Rect rect2 = new Rect(200, 200, 600, 600);
rect1.intersect(rect2);
此时,rect1 的 left、top、right、bottom 属性被改变了,分别为 200、200、400、400,
public void union(int left,int top,int right,int bottom){
if ((left < right) && (top < bottom)) {
if ((this.left < this.right) && (this.top < this.bottom)) {
if (this.left > left) this.left = left;
if (this.top > top) this.top = top;
if (this.right < right) this.right = right;
if (this.bottom < bottom) this.bottom = bottom;
} else {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
}
public void union(Rect r){
union(r.left, r.top, r.right, r.bottom);
}
union()方法是计算两个矩形的并集,传入一个新的 Rect,与当前 Rect 进行并集运算,并将结果保存在当前 Rect 对象中。比如有下面的代码段:
Rect rect1 = new Rect(0, 0, 400, 400);
Rect rect2 = new Rect(200, 200, 600, 600);
rect1.union(rect2);
运行后与交集一样,最终的结果保存在 rect1 对象中, rect1 的 left、top、right、bottom属性值分别为:0,0,600,600,也就是说,并集取的是四个方向的最大值。与 Rect 类类似的还有 RectF 类,RectF 类的代码实现与 Rect 如出一辙,主要的不同是 Rect的 left、top、right、bottom 四个成员变量为 int 类型,而 RectF 为 float 类型。在开发中,常常会出现 Rect 与 RectF 相互转换的情况,Rect 类中没有定义与 RectF 相关的任何信息,但在 RectF 类中,则定义了二者相互转换的方法。RectF 转换成 Rect。RectF 定义了两个名为 round 和 roundOut 的方法,round()方法将 RectF类的类型为 float 的 left、top、right、bottom 属性以四舍五入的方式转换成 int 再通过 Rect 类型的参数传回,roundOut()方法虽然和 round()差不多,但在某些情况下返回的矩形区域要大些。
public void round(Rect dst){
dst.set(FastMath.round(left), FastMath.round(top),
FastMath.round(right), FastMath.round(bottom));
}
public void roundOut(Rect dst){
dst.set((int) FloatMath.floor(left), (int) FloatMath.floor(top),
(int) FloatMath.ceil(right), (int) FloatMath.ceil(bottom));
}
public RectF(Rect r) {
if (r == null) {
left = top = right = bottom = 0.0f;
} else {
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
}
}
文章浏览阅读2.9k次,点赞8次,收藏14次。测试主要做什么?这完全都体现在测试流程中,同时测试流程是面试问题中出现频率最高的,这不仅是因为测试流程很重要,而是在面试过程中这短短的半小时到一个小时的时间,通过测试流程就可以判断出应聘者是否合适,故在测试流程中包含了测试工作的核心内容,例如需求分析,测试用例的设计,测试执行,缺陷等重要的过程。..._测试过程管理中包含哪些过程
文章浏览阅读870次,点赞16次,收藏19次。1.背景介绍政府数字化政务是指政府利用数字技术、互联网、大数据、人工智能等新技术手段,对政府政务进行数字化改革,提高政府工作效率,提升政府服务质量的过程。随着人工智能(AI)和机器学习(ML)技术的快速发展,政府数字化政务中的人工智能与机器学习应用也逐渐成为政府改革的重要内容。政府数字化政务的人工智能与机器学习应用涉及多个领域,包括政策决策、政府服务、公共安全、社会治理等。在这些领域,人工...
文章浏览阅读219次,点赞2次,收藏4次。系统主要的用户为用户、管理员,他们的具体权限如下:用户:用户登录后可以对管理员上传的学习视频进行学习。用户可以选择题型进行练习。用户选择小程序提供的考研科目进行相关训练。用户可以进行水平测试,并且查看相关成绩用户可以进行错题集的整理管理员:管理员登录后可管理个人基本信息管理员登录后可管理个人基本信息管理员可以上传、发布考研的相关例题及其分析,并对题型进行管理管理员可以进行查看、搜索考研题目及错题情况。_mysql刷题软件
文章浏览阅读1.4k次。myelipse里有UML1和UML2两种方式,UML2功能更强大,但是两者生成过程差别不大1.建立Test工程,如下图,uml包存放uml类图package com.zz.domain;public class User {private int id;private String name;public int getId() {return id;}public void setId(int..._根据以下java代码画出类图
文章浏览阅读174次。需求:一个topic包含很多个表信息,需要自动根据json字符串中的字段来写入到hive不同的表对应的路径中。发送到Kafka中的数据原本最外层原本没有pkDay和project,只有data和name。因为担心data里面会空值,所以根同事商量,让他们在最外层添加了project和pkDay字段。pkDay字段用于表的自动分区,proejct和name合起来用于自动拼接hive表的名称为 ..._flume拦截器自定义开发 kafka
文章浏览阅读380次。原标题:Java Spring中同时访问多种不同数据库 多样的工作要求,可以使用不同的工作方法,只要能获得结果,就不会徒劳。开发企业应用时我们常常遇到要同时访问多种不同数据库的问题,有时是必须把数据归档到某种数据仓库中,有时是要把数据变更推送到第三方数据库中。使用Spring框架时,使用单一数据库是非常容易的,但如果要同时访问多个数据库的话事件就变得复杂多了。本文以在Spring框架下开发一个Sp..._根据输入的不同连接不同的数据库
文章浏览阅读3.6k次,点赞9次,收藏25次。本案例描述了晶振屏蔽以及开关电源变压器屏蔽对系统稳定工作的影响, 硬件设计时应考虑。_eft电路图
文章浏览阅读1.1k次。对于物料价格的更改,可以采取不同的手段:首先,我们来介绍MR21的方式。 需要说明的是,如果要对某一产品进行价格修改,必须满足的前提条件是: ■ 1、必须对价格生效的物料期间与对应会计期间进行开启; ■ 2、该产品在该物料期间未发生物料移动。执行MR21,例如更改物料1180051689的价格为20000元,系统提示“对于物料1180051689 存在一个当前或未来标准价格”,这是因为已经对该..._mr21 对于物料 zba89121 存在一个当前或未来标准价格
文章浏览阅读7.4k次,点赞3次,收藏13次。[文章导读]联想启天M420是一款商用台式电脑,预装的是win10系统,用户还是喜欢win7系统,该台式机采用的intel 8代i5 8500CPU,在安装安装win7时有很多问题,在安装win7时要在BIOS中“关闭安全启动”和“开启兼容模式”,并且安装过程中usb不能使用,要采用联想win7新机型安装,且默认采用的uefi+gpt模式,要改成legacy+mbr引导,那么联想启天M420台式电..._启天m420刷bios
文章浏览阅读2.7k次,点赞2次,收藏9次。一,为什么要冗余数据互联网数据量很大的业务场景,往往数据库需要进行水平切分来降低单库数据量。水平切分会有一个patition key,通过patition key的查询能..._保证冗余性
文章浏览阅读88次。是时候闭环Java应用了 原创 2016-08-16 张开涛 你曾经因为部署/上线而痛苦吗?你曾经因为要去运维那改配置而烦恼吗?在我接触过的一些部署/上线方式中,曾碰到过以下一些问题:1、程序代码和依赖都是人工上传到服务器,不是通过工具进行部署和发布;2、目录结构没有规范,jar启动时通过-classpath任意指定;3、fat jar,把程序代码、配置文件和依赖jar都打包到一个jar中,改配置..._那么需要把上面的defaultjavatyperesolver类打包到插件中
文章浏览阅读909次。1.得下载一个番茄插件,按alt+g才可以有函数跳转功能。2.不安装番茄插件,按F12也可以有跳转功能。3.进公司的VS工程是D:\sync\build\win路径,.sln才是打开工程的方式,一个是VS2005打开的,一个是VS2013打开的。4.公司库里的线程接口,在CmThreadManager.h 里,这个里面是我们的线程库,可以直接拿来用。CreateUserTaskThre..._番茄助手颜色