在Android上,如何绘制类似pygame Rect的矩形?(x,y,w,h)

在Android上,如何绘制类似pygame Rect的矩形?(x,y,w,h),android,position,height,width,rect,Android,Position,Height,Width,Rect,有没有办法在Android中以以下模式绘制矩形,而不是“左、上、右、下”?问题是我使用的是随机坐标: Rect e = new Rect(random.nextInt(300)+20,20,random.nextInt(300)+45,70); 而且很难跟踪第一个左随机位置,将其包含在右随机位置的宽度中。在“x,y,w,h”中,很容易应用碰撞测试: if ((((p.left+p.width())>e.left)&&(p.left<(e.left+e.width()

有没有办法在Android中以以下模式绘制矩形,而不是“左、上、右、下”?问题是我使用的是随机坐标:

Rect e = new Rect(random.nextInt(300)+20,20,random.nextInt(300)+45,70);
而且很难跟踪第一个左随机位置,将其包含在右随机位置的宽度中。在“x,y,w,h”中,很容易应用碰撞测试:

if ((((p.left+p.width())>e.left)&&(p.left<(e.left+e.width())))&&
       (((p.top+p.height())>e.top)&&(p.top<(e.top+e.height())))) {
    gameScreen = 2;
}

if(((p.left+p.width())>e.left)&&&(p.lefte.top)&&(p.top只需将随机数移到rect的构造函数之外

int left = random.nextInt(300)+20;
int right = left + 20;
int top = random.nextInt(300)+45;
int bottom =  top + 70;

Rect e = new Rect(left, top, right, bottom);