マップビューにマーカーを配置し、マーカーに数字を書き込む必要があります。私はそれを行いましたが、テキストの配置は解像度によって異なります。以下は参照コードです
float xVal = (float) curScreenCoords.x; // Point curScreenCoords
float yVal = (float) curScreenCoords.y-20; // Point curScreenCoords
Bitmap bitmap = BitmapFactory.decodeResource ( context.getResources() , ( R.drawable.pin_number ) ) ;
canvas.drawBitmap(bitmap, xVal, yVal, getInnerPaint());
public Paint getInnerPaint() {
if (innerPaint == null) {
innerPaint = new Paint();
}
innerPaint.setARGB(255, 117, 161, 220); // blue
innerPaint.setAntiAlias(true);
innerPaint.setStyle(Style.FILL);
return innerPaint;
}
canvas.drawText(String.valueOf(10), xVal+20, yVal+22, getCountPaint()); // 10 is just for example, it can vary to one digit to two to three
public Paint getCountPaint() {
if (innerPaint == null) {
innerPaint = new Paint();
}
innerPaint.setARGB(255, 255, 255, 255);
innerPaint.setAntiAlias(true);
innerPaint.setStyle(Style.FILL);
innerPaint.setTextSize(12f);
innerPaint.setTextAlign(Align.CENTER);
return innerPaint;
}
テキストの配置を除いて、すべてが正常に機能します。このコードは、480*800の解像度で正常に機能します。テキストはキャンバスの中央に完全に配置されます。x、yの位置は画像では完璧ですが、320*480では完璧に見えません。この解像度では、テキストのx位置とy位置が異なって見えます。誰かが私に何が間違っているのかを正確に提案できますか?異なるサイズのデバイスで同じことを行うための基本はありますか?前もって感謝します。