전 전화기 화면에 6 각형 그리드를 그립니다. Canvas
을 사용하여 여섯 줄을 그려서 육각형을 그립니다. 너무 많은 줄이 그려져 앱이 응답하지 않습니다. 응용 프로그램은 이제 충돌하지 않는안드로이드 - 캔버스로 선 그리기
06-22 14:11:46.664: A/libc(5743): Fatal signal 6 (SIGABRT) at 0x0000166f (code=-6), thread 5743 (.nadeem.sensus4)
있지만,이 그리드를 그리는 너무 많은 시간이 소요 :이어야가 내 넥서스 4 그렇지 않으면 응용 프로그램이 오류로 추락 작동하도록 내가 android:HardwareAccelerated=false
을해야했다.
public DrawView(Context context, Hexagon hex) {
super(context);
this.context = context;
setLayerType(View.LAYER_TYPE_HARDWARE, null);
this.hex = hex;
}
@Override
public void onDraw(Canvas canvas) {
double xOff = Math.cos(Math.PI/6) * hex.radius;//radius is 12 for now
double yOff = Math.sin(Math.PI/6) * hex.radius; // third of the hex
// height
for (int i = 0; i < 60; ++i) {
for (int j = 0; j < 40; ++j) {
double xPos = j * xOff * 2;
if (i % 2 != 0) { // if the current line is not even
xPos += xOff; // extra offset of half the width on x axis
}
double yPos = i * yOff * 3;
createHexagon(xPos, // X pos for hexagon center on the scene
yPos, canvas);
}
}
}
public void createHexagon(double x, double y, Canvas canvas) {
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
// paint.setStyle(Style.FILL);
for (int i = 0; i < 6; i++) {
double angle = 2 * Math.PI/6 * (i + 0.5);
double x_i = x + hex.radius * Math.cos(angle);
double y_i = y + hex.radius * Math.sin(angle);
if (i == 0)
wallpath.moveTo((float) x_i, (float) y_i);
else
wallpath.lineTo((float) x_i, (float) y_i);
}
canvas.drawPath(wallpath, paint);
canvas = null;
}
나는 성능이 그리드를 달성하기 위해 다른 대체 방법을 높일 수있는 방법이 있는지 물어보고 싶은 :이 그리드를 끌어 내있는 CustomView의 코드입니다.
왜 육각형으로 반복 비트 맵을 그리지 않으시겠습니까? – pskink
@pskink 육각형의 모든 꼭지점의 좌표를 원합니다. – Naddy
그 점을 이해하지 못합니다, 죄송합니다 ... – pskink