Rect是一个final类,不属于被继承,实现Parcelable接口执行序列化,声明public作用域的四个整型属性:left、top、right和bottom,用来记录View矩形局域的四个顶点坐标。

  1. public Rect() {}

1、创建一个空的Rect对象,left、top、right和bottom的默认值为0

  1. public Rect(int left, int top, int right, int bottom) {
  2. this.left = left;
  3. this.top = top;
  4. this.right = right;
  5. this.bottom = bottom;
  6. }

2、创建一个指定坐标值的Rect对象,left、top、right和bottom为指定值

  1. public Rect(Rect r) {
  2. if (r == null) {
  3. left = top = right = bottom = 0;
  4. } else {
  5. left = r.left;
  6. top = r.top;
  7. right = r.right;
  8. bottom = r.bottom;
  9. }
  10. }

3、使用已知的Rect,创建一个新的Rect对象,left、top、right和bottom为已知的Rect包含的值

  1. @Override
  2. public boolean equals(Object o) {
  3. if (this == o) return true;
  4. if (o == null || getClass() != o.getClass()) return false;
  5. Rect r = (Rect) o;
  6. return left == r.left && top == r.top && right == r.right && bottom == r.bottom;
  7. }

4、判断当前Rect与指定的o是否同一个,相同的条件:属于同一个对象或者两者left、top、right或bottom属性值一样

  1. @Override
  2. public int hashCode() {
  3. int result = left;
  4. result = 31 * result + top;
  5. result = 31 * result + right;
  6. result = 31 * result + bottom;
  7. return result;
  8. }

5、计算Rect属性值的散列码

  1. @Override
  2. public String toString() {
  3. StringBuilder sb = new StringBuilder(32);
  4. sb.append("Rect("); sb.append(left); sb.append(", ");
  5. sb.append(top); sb.append(" - "); sb.append(right);
  6. sb.append(", "); sb.append(bottom); sb.append(")");
  7. return sb.toString();
  8. }

6、以Rect(left,top-right,bottom)的格式返回矩形四个坐标值

  1. public String toShortString(StringBuilder sb) {
  2. sb.setLength(0);
  3. sb.append('['); sb.append(left); sb.append(',');
  4. sb.append(top); sb.append("]["); sb.append(right);
  5. sb.append(','); sb.append(bottom); sb.append(']');
  6. return sb.toString();
  7. }

7、以[left,top] [right,bottom]的格式返回矩形四个坐标值,即矩形区域左上角和右下角坐标

  1. public String toShortString() {
  2. return toShortString(new StringBuilder(32));
  3. }

8、以[left,top] [right,bottom]的格式返回矩形四个坐标值,即矩形区域左上角和右下角坐标,和上述方法一样

  1. public String flattenToString() {
  2. StringBuilder sb = new StringBuilder(32);
  3. // WARNING: Do not change the format of this string, it must be
  4. // preserved because Rects are saved in this flattened format.
  5. sb.append(left);
  6. sb.append(' ');
  7. sb.append(top);
  8. sb.append(' ');
  9. sb.append(right);
  10. sb.append(' ');
  11. sb.append(bottom);
  12. return sb.toString();
  13. }

9、以left top right bottom的格式返回矩形四个坐标值,即平铺的格式,比如:0 0 400 400或 100 100 800 300

  1. public static Rect unflattenFromString(String str) {
  2. Matcher matcher = UnflattenHelper.getMatcher(str);
  3. if (!matcher.matches()) {
  4. return null;
  5. }
  6. return new Rect(Integer.parseInt(matcher.group(1)),
  7. Integer.parseInt(matcher.group(2)),
  8. Integer.parseInt(matcher.group(3)),
  9. Integer.parseInt(matcher.group(4)));
  10. }

10、给定一个平铺格式的字符串,比如:0 0 400 400,判断是否合法,然后转换为一个Rect对象

  1. public void printShortString(PrintWriter pw) {
  2. pw.print('['); pw.print(left); pw.print(',');
  3. pw.print(top); pw.print("]["); pw.print(right);
  4. pw.print(','); pw.print(bottom); pw.print(']');
  5. }

11、将Rect包含的属性值以[left,top] [right,bottom]的格式写入给定的PrintWriter流中

  1. public final boolean isEmpty() {
  2. return left >= right || top >= bottom;
  3. }

12、判断Rect是否一个空对象,即包含的属性值是否不为0

  1. public final int width() {
  2. return right - left;
  3. }

13、计算矩形区域的宽度

  1. public final int height() {
  2. return bottom - top;
  3. }

14、计算矩形区域的高度

  1. public final int centerX() {
  2. return (left + right) >> 1;
  3. }

15、计算矩形区域的水平中心点,计算结果为分数则返回最接近的整型数,例如:水平中心点400

  1. public final int centerY() {
  2. return (top + bottom) >> 1;
  3. }

16、计算矩形区域的垂直中心点,计算结果为分数则返回最接近的整型数,例如:垂直中心点850

  1. public final float exactCenterX() {
  2. return (left + right) * 0.5f;
  3. }

17、计算矩形区域的水平中心点,返回结果float类型,例如:水平中心点400.0

  1. public final float exactCenterY() {
  2. return (top + bottom) * 0.5f;
  3. }

18、计算矩形区域的垂直中心点,返回结果float类型,例如:垂直中心点850.0

  1. public void setEmpty() {
  2. left = right = top = bottom = 0;
  3. }

19、将Rect对象包含的属性值设置为0

  1. public void set(int left, int top, int right, int bottom) {
  2. this.left = left;
  3. this.top = top;
  4. this.right = right;
  5. this.bottom = bottom;
  6. }

20、将Rect的属性值设置为指定的值

  1. public void set(Rect src) {
  2. this.left = src.left;
  3. this.top = src.top;
  4. this.right = src.right;
  5. this.bottom = src.bottom;
  6. }

21、复制指定的Rect对象包含的属性值

  1. public void offset(int dx, int dy) {
  2. left += dx;
  3. top += dy;
  4. right += dx;
  5. bottom += dy;
  6. }

22、在当前矩形区域的水平方向、垂直方向分别增加dx、dy距离,即扩展

  1. public void offsetTo(int newLeft, int newTop) {
  2. right += newLeft - left;
  3. bottom += newTop - top;
  4. left = newLeft;
  5. top = newTop;
  6. }

23、在当前矩形区域的水平方向、垂直方向分别偏移dx、dy距离,即水平平移dx、垂直平移dy

  1. public void inset(int dx, int dy) {
  2. left += dx;
  3. top += dy;
  4. right -= dx;
  5. bottom -= dy;
  6. }

24、在当前矩形区域的水平方向、垂直方向分别减少dx、dy距离,即缩小

  1. public boolean contains(int x, int y) {
  2. return left < right && top < bottom  // check for empty first
  3. && x >= left && x < right && y >= top && y < bottom;
  4. }

25、计算指定的坐标(x,y)是否包含在矩形区域范围内,包含返回true,否则返回false

  1. public boolean contains(int left, int top, int right, int bottom) {
  2. // check for empty first
  3. return this.left < this.right && this.top < this.bottom
  4. // now check for containment
  5. && this.left <= left && this.top <= top
  6. && this.right >= right && this.bottom >= bottom;
  7. }

26、计算指定的left、top、right、bottom顶点是否包含在矩形区域范围内,包含返回true,否则返回false

  1. public boolean contains(Rect r) {
  2. // check for empty first
  3. return this.left < this.right && this.top < this.bottom
  4. // now check for containment
  5. && left <= r.left && top <= r.top && right >= r.right && bottom >= r.bottom;
  6. }

27、计算指定的Rect是否包含在矩形区域范围内,包含返回true,否则返回false

  1. public boolean intersect(int left, int top, int right, int bottom) {
  2. if (this.left < right && left < this.right && this.top < bottom && top < this.bottom) {
  3. if (this.left < left) this.left = left;
  4. if (this.top < top) this.top = top;
  5. if (this.right > right) this.right = right;
  6. if (this.bottom > bottom) this.bottom = bottom;
  7. return true;
  8. }
  9. return false;
  10. }

28、计算当前Rect与指定的left、top、right、bottom顶点是否存在交集区域,存在返回true并且返回指定坐标,否则返回false

  1. public boolean intersect(Rect r) {
  2. return intersect(r.left, r.top, r.right, r.bottom);
  3. }

29、计算当前Rect与指定的Rect是否存在交集区域,存在返回true并且返回指定坐标,否则返回false

  1. public boolean setIntersect(Rect a, Rect b) {
  2. if (a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom) {
  3. left = Math.max(a.left, b.left);
  4. top = Math.max(a.top, b.top);
  5. right = Math.min(a.right, b.right);
  6. bottom = Math.min(a.bottom, b.bottom);
  7. return true;
  8. }
  9. return false;
  10. }

30、计算指定的a、b是否存在交集区域,存在返回true并且返回最大坐标,否则返回false

  1. public boolean intersects(int left, int top, int right, int bottom) {
  2. return this.left < right && left < this.right && this.top < bottom && top < this.bottom;
  3. }

31、计算当前Rect与指定的left、top、right、bottom顶点是否存在交集区域,存在返回true并且不返回指定坐标,否则返回false

  1. public static boolean intersects(Rect a, Rect b) {
  2. return a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
  3. }

32、计算指定的a、b是否存在交集区域,存在返回true并且不返回最大坐标,否则返回false

  1. public void union(int left, int top, int right, int bottom) {
  2. if ((left < right) && (top < bottom)) {
  3. if ((this.left < this.right) && (this.top < this.bottom)) {
  4. if (this.left > left) this.left = left;
  5. if (this.top > top) this.top = top;
  6. if (this.right < right) this.right = right;
  7. if (this.bottom < bottom) this.bottom = bottom;
  8. } else {
  9. this.left = left;
  10. this.top = top;
  11. this.right = right;
  12. this.bottom = bottom;
  13. }
  14. }
  15. }

33、计算当前Rect与指定的left、top、right、bottom顶点是否存在集区域,存在更新当前矩形区域,否则不更新

  1. public void union(Rect r) {
  2. union(r.left, r.top, r.right, r.bottom);
  3. }

34、计算当前Rect与指定的Rect是否存在集区域,存在更新当前矩形区域,否则不更新

  1. public void union(int x, int y) {
  2. if (x < left) {
  3. left = x;
  4. } else if (x > right) {
  5. right = x;
  6. }
  7. if (y < top) {
  8. top = y;
  9. } else if (y > bottom) {
  10. bottom = y;
  11. }
  12. }

35、计算当前Rect与指定的坐标(x,y)是否存在集区域,存在更新当前矩形区域,否则不更新

  1. public void sort() {
  2. if (left > right) {
  3. int temp = left;
  4. left = right;
  5. right = temp;
  6. }
  7. if (top > bottom) {
  8. int temp = top;
  9. top = bottom;
  10. bottom = temp;
  11. }
  12. }

36、排序当前矩形区域,符合:left

  1. public void scale(float scale) {
  2. if (scale != 1.0f) {
  3. left = (int) (left * scale + 0.5f);
  4. top = (int) (top * scale + 0.5f);
  5. right = (int) (right * scale + 0.5f);
  6. bottom = (int) (bottom * scale + 0.5f);
  7. }
  8. }

37、按照指定的值缩放当前矩形区域

  1. public void scaleRoundIn(float scale) {
  2. if (scale != 1.0f) {
  3. left = (int) Math.ceil(left * scale);
  4. top = (int) Math.ceil(top * scale);
  5. right = (int) Math.floor(right * scale);
  6. bottom = (int) Math.floor(bottom * scale);
  7. }
  8. }

38、按照指定的值缩放当前矩形区域

Rect、RectF方法解析相关推荐

  1. Peer J:整合高通量绝对丰度定量方法解析土壤细菌群落及动态

    本文转自"上海天昊生物",已获授权 英文题目: Assessing soil bacterial community and dynamics by integrated high ...

  2. leaq c 汇编语言,汇编语言lea指令使用方法解析

    这篇文章主要介绍了汇编语言lea指令使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 lea指令变种(按大小分类): leaw #2个字节 ...

  3. python类中方法的执行顺序-浅谈Python的方法解析顺序(MRO)

    方法解析顺序, Method Resolution Order 从一段代码开始 考虑下面的情况: class A(object): def foo(self): print('A.foo()') cl ...

  4. 【Android NDK 开发】JNI 方法解析 ( 字符串数组参数传递 | 字符串遍历 | 类型强转 | Java 字符串与 C 字符串转换 | 字符串释放 )

    文章目录 I . C/C++ 中的 Java 字符串数组类型 II . 获取字符串数组长度 III . 获取字符串数组元素 IV . 类型强转 ( jobject -> jstring ) V ...

  5. 【Android NDK 开发】JNI 方法解析 ( JNIEnv *env 参数 )

    文章目录 一. JNI 方法解析 二. JNIEnv *env 参数解析 三. C 语言 环境中 JNIEnv *env 参数解析 四. C ++ 环境中 JNIEnv *env 参数解析 总结 : ...

  6. 【Android 多媒体开发】 MediaPlayer 状态机 接口 方法 解析

    作者 : 韩曙亮 转载请著名出处 :  http://blog.csdn.net/shulianghan/article/details/38487967 一. MediaPlayer 状态机 介绍 ...

  7. python不定长参数怎么相加_python函数不定长参数使用方法解析

    这篇文章主要介绍了python函数不定长参数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 pathon中的函数可以使用不定长参数,可以 ...

  8. java修改文件的大小限制_Struts2修改上传文件大小限制方法解析

    首先struts上传最大大小由两个地方决定. struts.multipart.maxSize决定整个post的form最大是多大,所以这个限制是最初的.默认大小是接近2M,在struts的defau ...

  9. java list 删除 遍历_Java list利用遍历进行删除操作3种方法解析

    Java list利用遍历进行删除操作3种方法解析 这篇文章主要介绍了Java list利用遍历进行删除操作3种方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需 ...

  10. 通过豆瓣电影的多方法解析,带你学会爬虫的所有解析方法

    文章目录 豆瓣电影的多方法解析 1. 分析网页,确认爬取目标的数据类型. 打开 [目标url](https://movie.douban.com/tag/Top100), 定位数据位置 定位需要的数据 ...

最新文章

  1. 【转】目录 aspnet_client是什么?
  2. 为了让你在“口袋奇兵”聊遍全球,Serverless 做了什么?
  3. python混沌时间序列分析_用Python进行时间序列分析
  4. Flex 中 12 个简单实用的小技巧
  5. HDU 6155 Subsequence Count(矩阵乘法+线段树+基础DP)
  6. 这样的促销海报,还怕卖不出去?
  7. 全球闪存供应紧张 新iPhone涨价只是开始
  8. 拓端tecdat|R语言使用 LOWESS技术图分析逻辑回归中的函数形式
  9. 纯HTML个人简历模板代码
  10. 超全面超详细的Linux学习入门系列教程
  11. HTML嵌入JavaScript代码的三种方式
  12. 机器学习_深度学习毕设题目汇总——漫画
  13. 程序员如何提高编程时打字速度的5个Tips
  14. 存款利息python题_c#入门之实现简易存款利息计算器示例
  15. DDOS流量攻击如何防御分析以及被攻击的解决方案
  16. 【ceph相关】ceph常见问题处理
  17. python web开发屠龙刀flask
  18. qc35 说明书_BOSE QC35
  19. vm10升级到16的问题
  20. 软件-开发软件:Android Studio

热门文章

  1. 梦幻西游战斗中服务器维护,梦幻西游10月22日维护公告 连续战斗自动问题修复...
  2. 火车头如何把标题加html标签,火车采集器怎么编辑标签 火车采集器标签编辑教程...
  3. 为何要使用加密邮箱?
  4. 禁止 Windows 10 和 Windows Server 自动更新
  5. 章文嵩坐镇淘宝双11流量作战室
  6. npm设置为淘宝镜像地址
  7. 两平面平行但不重合的条件是_____怎样证明平行
  8. golang打包流程
  9. android apk如何压缩包,Android 打包Apk太大 如何进行压缩APK文件
  10. 编曲宿主DAW是什么 2023年编曲宿主软件哪个好用