本文整理了Java中android.graphics.Rect.intersect
方法的一些代码示例,展示了Rect.intersect
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rect.intersect
方法的具体详情如下:
包路径:android.graphics.Rect
类名称:Rect
方法名:intersect
[英]If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. No check is performed to see if either rectangle is empty. Note: To just test for intersection, use #intersects(Rect,Rect).
[中]如果左、上、右、下指定的矩形与该矩形相交,则返回true并将该矩形设置为该相交,否则返回false且不更改该矩形。不执行任何检查以查看任一矩形是否为空。注意:要测试交叉点,请使用#intersects(Rect,Rect)。
代码示例来源:origin: nickbutcher/plaid
/**
* Determines if two views intersect in the window.
*/
public static boolean viewsIntersect(View view1, View view2) {
if (view1 == null || view2 == null) return false;
final int[] view1Loc = new int[2];
view1.getLocationOnScreen(view1Loc);
final Rect view1Rect = new Rect(view1Loc[0],
view1Loc[1],
view1Loc[0] + view1.getWidth(),
view1Loc[1] + view1.getHeight());
int[] view2Loc = new int[2];
view2.getLocationOnScreen(view2Loc);
final Rect view2Rect = new Rect(view2Loc[0],
view2Loc[1],
view2Loc[0] + view2.getWidth(),
view2Loc[1] + view2.getHeight());
return view1Rect.intersect(view2Rect);
}
代码示例来源:origin: xinghongfei/LookLook
/**
* Determines if two views intersect in the window.
*/
public static boolean viewsIntersect(View view1, View view2) {
if (view1 == null || view2 == null) return false;
final int[] view1Loc = new int[2];
view1.getLocationOnScreen(view1Loc);
final Rect view1Rect = new Rect(view1Loc[0],
view1Loc[1],
view1Loc[0] + view1.getWidth(),
view1Loc[1] + view1.getHeight());
int[] view2Loc = new int[2];
view2.getLocationOnScreen(view2Loc);
final Rect view2Rect = new Rect(view2Loc[0],
view2Loc[1],
view2Loc[0] + view2.getWidth(),
view2Loc[1] + view2.getHeight());
return view1Rect.intersect(view2Rect);
}
代码示例来源:origin: journeyapps/zxing-android-embedded
boolean intersects = intersection.intersect(surface);
代码示例来源:origin: robolectric/robolectric
@Test
public void intersectRect() {
Rect a = new Rect(0, 0, 10, 10);
Rect b = new Rect(5, 0, 15, 10);
assertThat(a.intersect(b)).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void intersectCoordinates() {
Rect r = new Rect(0, 0, 10, 10);
assertThat(r.intersect(5, 0, 15, 10)).isTrue();
}
代码示例来源:origin: stackoverflow.com
public Boolean CollisionTest (Rect one, Rect two) {
if (one.intersect(two)) {
collided = true;
} else {
collided = false;
}
return(collided);
}
代码示例来源:origin: stackoverflow.com
Rect scrollViewRect; // the bounds of your scrollview
Rect tooltipRect; // the bounds of your tooltip
bool intersects = tooltipRect.intersect(scrollViewRect)
if(intersects)
{
canvas.clipRect(tooltipRect, Region.Op.REPLACE);
draw(canvas);
}
代码示例来源:origin: stackoverflow.com
Rect rect1, rect2;
if(rect1.intersect(rect2)
//do something
代码示例来源:origin: stackoverflow.com
public int[] extractY(byte[] yuv420, Size szYuv, Rect rcY)
{
rcY.intersect(0, 0, szYuv.width, szYuv.height);
final int[] res = int[rcY.width()*rcY.height()];
int yCount = 0;
for (int row=rcY.left; row<rcY.right; row++)
{
for (int col=rcY.top; col<rcY.bottom; col++)
{
res[yCount++] = yuv420[col+rcY.left+(row+rcY.top)*szYuv.width];
}
}
return res;
}
代码示例来源:origin: stackoverflow.com
public Rect getBounds(){ //put this in your sprite and enemy-class.
return new Rect(x, y, x+width, y+height);
}
Public void checkCollision(){
for (int i = 0; i<spriteArray.size(); i++){
Rect mySprite = spriteArray.get(i).getBounds(); //create rect for every sprite in array
for (int j = 0; j<spriteArray.size(); i++){
Rect myOtherSprite = spriteArray.get(i).getBounds();
if(mySprite.intersect(myOtherSprite)){ //check if they touch
//Todo code here
}
}
}
}
代码示例来源:origin: stackoverflow.com
int[] firstPosition = new int[2];
int[] secondPosition = new int[2];
firstView.getLocationOnScreen(firstPosition);
secondView.getLocationOnScreen(secondPosition);
// Rect constructor parameters: left, top, right, bottom
Rect rectFirstView = new Rect(firstPosition[0], firstPosition[1],
firstPosition[0] + firstView.getMeasuredWidth(), firstPosition[1] + firstView.getMeasuredHeight());
Rect rectSecondView = new Rect(secondPosition[0], secondPosition[1],
secondPosition[0] + secondView.getMeasuredWidth(), secondPosition[1] + secondView.getMeasuredHeight());
return rectFirstView.intersect(rectSecondView);
代码示例来源:origin: stackoverflow.com
static boolean collide(Rect r1, Rect r2){
if(r1.intersect(r2) || r1.contains(r2) || r2.contains(r1)){
return true;
}
return false;
}
代码示例来源:origin: stackoverflow.com
tw.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Rect recTest1 = new Rect();
img1.getDrawingRect(recTest1);
Rect recTest2 = new Rect();
img2.getDrawingRect(recTest2);
System.out.println("Test : "+recTest1.intersect(recTest2));
}
});
代码示例来源:origin: stackoverflow.com
va=ValueAnimator.ofFloat(0.0f,size.y);
va.setDuration(5000);
va.setRepeatCount(va.INFINITE);
va.setRepeatMode(va.REVERSE);
va.start();
va.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// TODO Auto-generated method stub
bullet[0].setTranslationY((Float) va.getAnimatedValue());
Rect R11=new Rect(bullet[0].getLeft(),bullet[0].getTop()+(int)bullet[0].getTranslationY(),bullet[0].getRight(),bullet[0].getBottom()+(int)bullet[0].getTranslationY());
Rect R21=new Rect(ball.getLeft(), ball.getTop(), ball.getRight(), ball.getBottom());
if(R11.intersect(R21))
va.cancel();
}
});
代码示例来源:origin: stackoverflow.com
public boolean CheckCollision(View v1,View v2) {
Rect R1=new Rect(v1.getLeft(), v1.getTop(), v1.getRight(), v1.getBottom());
Rect R2=new Rect(v2.getLeft(), v2.getTop(), v2.getRight(), v2.getBottom());
return R1.intersect(R2);
}
代码示例来源:origin: stackoverflow.com
private boolean checkCollision(View v1, View v2)
{
int leftMargin = ((RelativeLayout.LayoutParams) v1.getLayoutParams()).leftMargin;
int topMargin = ((RelativeLayout.LayoutParams) v1.getLayoutParams()).topMargin;
Rect r1 = new Rect(root.getPaddingLeft() + leftMargin, root.getPaddingTop() + topMargin,
root.getPaddingLeft() + leftMargin + v2.getWidth(), root.getPaddingTop() + topMargin + v2.getHeight());
Rect r2 = new Rect(v2.getLeft(), v2.getTop(), v2.getRight(), v2.getBottom());
return r1.intersect(r2);
}
代码示例来源:origin: stackoverflow.com
private boolean checkHit(View v, View hit){
Rect rv = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
Rect rhit = new Rect(hit.getLeft(), hit.getTop(), hit.getRight(), hit.getBottom());
return rv.intersect(rhit);
}
代码示例来源:origin: stackoverflow.com
private boolean viewsOverlap(View v1, View v2) {
int[] v1_coords = new int[2];
v1.getLocationOnScreen(v1_coords);
int v1_w = v1.getWidth();
int v1_h = v1.getHeight();
Rect v1_rect = new Rect(v1_coords[0], v1_coords[1], v1_coords[0] + v1_w, v1_coords[1] + v1_h);
int[] v2_coords = new int[2];
v2.getLocationOnScreen(v1_coords);
int v2_w = v2.getWidth();
int v2_h = v2.getHeight();
Rect v2_rect = new Rect(v2_coords[0], v2_coords[1], v2_coords[0] + v2_w, v2_coords[1] + v2_h);
return v1_rect.intersect(v2_rect) || v1_rect.contains(v2_rect) || v2_rect.contains(v1_rect);
}
代码示例来源:origin: com.harium.android/core
/**
* If the specified rectangle intersects this rectangle, return true and set
* this rectangle to that intersection, otherwise return false and do not
* change this rectangle. No check is performed to see if either rectangle
* is empty. To just test for intersection, use intersects()
*
* @param r The rectangle being intersected with this rectangle.
* @return true if the specified rectangle and this rectangle intersect
* (and this rectangle is then set to that intersection) else
* return false and do not change this rectangle.
*/
@CheckResult
public boolean intersect(Rect r) {
return intersect(r.left, r.top, r.right, r.bottom);
}
代码示例来源:origin: stackoverflow.com
private boolean isViewOverlapping(View firstView, View secondView) {
final int[] location = new int[2];
firstView.getLocationInWindow(location);
Rect rect1 = new Rect(location[0], location[1],location[0] + firstView.getWidth(), location[1] + firstView.getHeight());
secondView.getLocationInWindow(location);
Rect rect2 = new Rect(location[0], location[1],location[0] + secondView.getWidth(), location[1] + secondView.getHeight());
return rect1.intersect(rect2);
// return (rect1.contains(rect2)) || (rect2.contains(rect1));
}
内容来源于网络,如有侵权,请联系作者删除!