2011.07.20(2)——— android 计算当前坐标是否在view内

    2011.07.20(2)——— android 计算当前坐标是否在view内
参考: http://blog.csdn.net/wong_judy/article/details/5942793

例如一个imageview

rectf这个类包含一个矩形的四个单精度浮点坐标。矩形通过上下左右4个边的坐标来表示一个矩形。这些坐标值属性可以被直接访问,用width()和 height()方法可以获取矩形的宽和高

1、首先获得这个imageview的最小矩形

private final rectf mregion = new rectf();。。。mregion.set(location[0], location[1], location[0] + mright - mleft,                    location[1] + mbottom - mtop);


有三个方法 可以初始化rectf 当然你也可以用构造函数
set(left, top, right, bottom)set(rect r)set(rectf f)


2、判断

boolean inregion = region.contains(ev.getrawx(), ev.getrawy());


public boolean contain(rectf r);
判断一个矩形是否在此矩形内,如果在这个矩形内或者和这个矩形等价则返回true,同样类似的方法还有
public boolean contain(float left,float top,float right,float bottom)和public boolean contain(float x,float y)。

p
ublic void union(float x,float y)
更新这个矩形,使它包含矩形自己和(x,y)这个点。





 

你可能感兴趣的:(java,工作)