Android自定义view之 Graphics2D Api(上)

**

Point 和 PointF 类

**
Point是graphics2D中最简单的结构,代表一个“点”。
安卓中的坐标系跟数学中的不一样,安卓中x轴向右为正向左为负,y轴向下为正向上为负。当x,y为正是点在屏幕内,否则在屏幕外。
这个类有两个属性,分别是:X坐标和y坐标。

构造函数有三个:Point(),Point(int x,int y),Point(Point p)

主要方法有:

Public void set(x,y);设置x,y的坐标

Public final void offset(int dx,int dy);改变x,y的偏移量,正负号决定偏移方向
//取反坐标值
Public final void negate(){
x = -x;
y = -y
};

Point类和android.graphics.PointF类似,不同点是前者坐标值的类型是int型,而后者的坐标值是float型。除此之外PointF类多加了几个方法,比如:

Public final float length();返回(0,0)点到该点的距离。

Public static float length(float x,float y);返回(0,0)点到(x,y)点的距离。

**

Rect和RectF

**
Rect 定义一个矩形结构,定义了left,top ,right,bottom四个成员变量。
left 矩形左边距离x轴的距离
right 矩形右边距离x轴的距离
top 矩形上边距离x轴的距离
bottom 矩形底部距离x轴的距离
构造方法:
Rect();
Rect(Rect src);
Rect(int left,int right,int top,int bottom);
主要方法:
public final boolean isEmpty();//判断矩形是否为空也就是面积为零或者无效矩形
public final int width();
public final int height();
public final int centerX(); 中心点的x左标
public final int centerY();
public final float exactCenterX() //精确的中心点X坐标 返回值为float
public final float exactCenterY();
public void setEmpty() //将left right top bottom 设置为0
public void set(int left,int right,int top,int bottom)//重新给矩形赋值
public void set(Rect src)
public void offset(int dx,int dy){ //左右移动dx的距离 上下移动 dy个距离
left += dx;
right+= dx;
top+= dy;
bottom+= dy;
}
public void offsetTo(int dx,int dy){ //左移dx的位置 上移动 dy的位置
left = dx;
right+= dx-left;
top= dy;
bottom+= dy-top;
}
public void inset(int x,int y)缩放
public Boolean contains(int x,int y)//判断点是否位于矩形内
public Boolean contains(int left,int right,int top,int bottom)//判断矩形是否位于矩形内
public Boolean contains(Rect src)
public Boolean intersect(int left,int right,int top,int bottom)//交际运算,并将运算结果保存在当前的矩形中。
public Boolean union(int left,int right,int top,int bottom)//并际运算,并将运算结果保存在当前的矩形中。
Rect类还有一个RectF类代码和Rect类似,只是left right top bottom成员变量的类型不在是int而是float类型。RectF类有两方法将RectF转化为Rect类。
public void round(Rect dst);
public void roundOut(Rect dst);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值