我想做一个测试触摸屏应用程序,比如三星设备诊断工具。谁能把源代码发给我?
我想喜欢它。
http://i.stack.imgur.com/7KgKW.jpg

最佳答案

这个应用程序的开发很容易。你需要明白:
如何获取click的坐标。

@Override
public boolean onTouchEvent(MotionEvent event) {
    int x = (int)(event.getX()/tileSize);
    int y = (int)(event.getY()/tileSize);
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        map[x][y] = true;
        break;
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
    }
return false;
}

重写方法ondraw,以绘制矩形。
  private void init(){
  tileSize = 10;

  paint1 = new Paint();
  paint1.setColor(Color.BLUE);
  paint1.setStrokeWidth(10);
  paint1.setStyle(Paint.Style.STROKE);

  paint2 = new Paint();
  paint2.setColor(Color.RED);
  paint2.setStrokeWidth(10);
  paint2.setStyle(Paint.Style.STROKE);

 }

 @Override
 protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
for (int i = 0; i < x; i++){
    for (int j = 0; j < y; j++){
        Paint p = null;
        if(map[i][j]){
        p=paint1;
        }else{
        p=paint2;
        }
        canvas.drawRect(i*tileSize, j*tileSize, tileSize, tileSize, paint);
    }

}
}
}

09-16 19:58