마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

드래그로 지나간 사각형 색칠하기

0 추천
안녕하세요 초보 개발자입니다.
지금 만들고있는 어플이 View를 여러개의 사각형으로 조각내고
드래그로 그사각형쪽에 들어갈때마다 색칠되게 만드는건데요
View를 따로만들어서 drawrect를 사용해 색칠하다보니 빠른속도로 칠하지 못합니다.
조각내는 사각형 갯수가 약 100개 이상 하려고 하거든요....
 
혹시 다른방법이나 혹은 개선 방법 있을까요? 고수님들의 조언 부탁드립니다.
아래는 ondraw 에서 드래그시 색칠하는 부분입니다.
 
  for (int i = 0; i < x; i++) {
   for (int j = 0; j < y; j++) {
    Left = (int) width / x + (x / 10) - 1;
    Top = (int) height / y + (y / 10) - 1;
    rect[i][j] = new MyRectangle();
    if (j == 0)
     rect[i][j].setRect(i * Left, (j * Top), (int) width, (int) height - 1);
    if (i == (x - 1) && j == (y - 1))
     rect[i][j].setRect(i * Left, j * Top, (int) width, (int) height - 1);
    else if (j == (y - 1))
     rect[i][j].setRect(i * Left, j * Top, (i + 1) * Left, (int) height - 1);
    else if (i == (x - 1))
     rect[i][j].setRect(i * Left, j * Top, (int) width, (j + 1) * Top);
    else
     rect[i][j].setRect(i * Left, j * Top, (i + 1) * Left, (j + 1) * Top);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setStrokeWidth(2);
    paint.setStyle(Style.STROKE);
    canvas.drawRect(rect[i][j].getLeft(), rect[i][j].getTop(), rect[i][j].getRight(), rect[i][j].getBottom(), paint); // 사각형
    if (rect[i][j].ptInRect((int) (dx), (int) (dy)) || rect[i][j].ptInRect((int) (oldx), (int) (oldy))) {
 
     if (Drag == true) {
      if (rect[i][j].getSelect()) {
       rect[i][j].setSelect(false);
       rect[i][j].setFirst(0);
      }
     } else if (Drag == false) {
      if (!rect[i][j].getSelect()) {
       rect[i][j].setSelect(true);
       rect[i][j].setFirst(line);
       rect[i][j].setRED(GridActivity.red);
       rect[i][j].setGREEN(GridActivity.green);
       rect[i][j].setBLUE(GridActivity.blue);
 
      }
     }
    }
    Log.i("msg", "line = " + line);
    // Log.i("msg", "delay = " + delay);
 
    for (int lines = 1; lines < 100; lines++) {
     if (rect[i][j].getFirst() == lines) {// 선택된 부분 체크 , 사각형
      // 빨간색칠
      Paint apaint;
      apaint = new Paint();
      apaint.setStrokeWidth(5);
 
      apaint.setColor(Color.rgb(rect[i][j].getRED(), rect[i][j].getGREEN(), rect[i][j].getBLUE()));
      apaint.setStyle(Style.FILL);
 
      canvas.drawRect(rect[i][j].getLeft(), rect[i][j].getTop(), rect[i][j].getRight(), rect[i][j].getBottom(), apaint);
 
     }
    }
 
    // Log.i("msg", "blink = " + blink);
   }
  }
 

 

웰로우 (180 포인트) 님이 2015년 1월 5일 질문

1개의 답변

0 추천
SurfaceView를 사용해보세요.
안_드루이드 (14,510 포인트) 님이 2015년 1월 5일 답변
아직 초보자라서요... 조금만 더 자세히 부탁드립니다
...