내 화면을 직사각형으로 나눕니다. 그러나 for 루프를 사용하고 있으므로 매번 다시 작성하는 직사각형을 저장하지 않습니다. 배열과 같이 어떻게 저장합니까? 그런 다음 루프 내부for 루프에서 rects를 저장하는 방법
public void drawGrid() {
//android.os.Debug.waitForDebugger();
int height,width;
int column,row;
int maxColumn,maxRow;
maxColumn = 4;
maxRow = 4;
column = 0;
row = 0;
height = c.getHeight()/maxRow;
width = c.getWidth()/maxColumn;
Paint pg = new Paint();
Rect[] test[];
for(int i = 0;i < 5; i++) {
int srcX = column * width;
int srcY = row * height;
Rect src =new Rect(srcX,srcY,srcX + width, srcY +height);
pg.setColor(Color.WHITE);
pg.setStyle(Paint.Style.STROKE);
pg.setStrokeWidth(5);
c.drawRect(src, pg);
if (column == maxColumn && row == maxRow){
i = 5;
} else {i=0;}
if (column == maxColumn){
row = row + 1;
column = 0;
} else {column = column + 1;}
}
}
아마 그렇게하는 것이 더 나을 것이라고 생각했습니다. rects [maxColumn] [maxRow]와 같은 배열로 설정하려고합니다. 그리드에서 좌표계로 그들을 다시 호출 할 수 있습니다. 그래서 만들어지면 그냥 Rect [Column] [row]로 만듭니다. 그렇게 할 수 있을까요? – user1967326
그래, 할 수있어. 에서 편집했습니다. – kcoppock
정말 고마워요. – user1967326