我有兩個圖像一個圓形和一個箭頭。我計算當前GPS座標和地圖上選定的座標之間的距離。現在我需要將箭頭放在圓形圖像上並放在箭頭計算的距離上。我怎樣才能實現這個? 喜歡的東西如何在Android中創建自定義指南針?
編輯: 如何放置箭頭圖像中心和文字上的箭頭?
public class CompassOverlay extends Overlay
{
private float angle;
public CompassOverlay(float angle)
{
this.angle=angle;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
Bitmap back =BitmapFactory.decodeResource(mapView.getResources(),R.drawable.tfm_compass_back);
Bitmap arrowBitmap = BitmapFactory.decodeResource(mapView.getResources(),R.drawable.tfm_compass_arrow);
// Create blank bitmap of equal size for back
Bitmap canvasBitmap = back.copy(Bitmap.Config.ARGB_8888, true);
canvasBitmap.eraseColor(0x00000000);
// Create canvas
Canvas canvasBack = new Canvas(canvasBitmap);
// Create rotation matrix
Matrix rotateMatrix = new Matrix();
rotateMatrix.setRotate(angle, canvasBack.getWidth()/2, canvasBack.getHeight()/2);
canvas.drawBitmap(back, 0.0f, 0.0f, null);
// Draw bitmap onto canvas using matrix
canvasBack.drawBitmap(arrowBitmap, rotateMatrix, null);
BitmapDrawable bitmapDrawable= new BitmapDrawable(canvasBitmap);
canvas.drawBitmap(bitmapDrawable.getBitmap(), 0.0f, 0.0f, null);
return true;
}
}
http://developer.android.com/reference/android/graphics/Canvas.html #drawBitmap%28android.graphics.Bitmap,%20android.graphics.Rect,%20android.graphics.RectF,%20android.graphics.Paint%29 – 2012-09-09 09:02:36