如何使用 DrawRect 方法在画布上绘制一组矩形?我试图通过传递块的坐标来生成动态室内地图。
我想知道..如何在 for 循环中使用 drawRect 方法..!
我在 Luke Taylor 的帮助下上了两节课。(谢谢你..!:))
一个是坐标,另一个是名为 DrawMapActivity 的主类。现在我需要知道如何填充坐标数组???
包 itgsm.drawmap;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
public class DrawMapActivity extends Activity {
/** Called when the activity is first created. */
static Coordinates[] coordinates = new Coordinates[10]; // 10 is just an example
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
//
// }
public void onDraw(Canvas canvas) {
Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
myPaint.setStrokeWidth(8/*1 /getResources().getDisplayMetrics().density*/);
myPaint.setColor(0xffff0000); //color.RED
for(int i = 0; i < coordinates.length; i++) {
canvas.drawRect(new Rect(coordinates[i].getX(), coordinates[i].getY(), coordinates[i].getX() + 10,coordinates[i].getY() + 10), myPaint); // 10 is the dimension of your block
}
}
}