Android:自定义指南针图像仅部分重绘
我希望通过子类化 MyLocationOverlay 在 MapView 上绘制自己的指南针图像。自定义图像需要大于 MyLocationOverlay 显示的默认图像。我重写drawCompass并使用我自己的可绘制对象(位图)来绘制指南针:
@Override
protected void drawCompass(Canvas canvas, float bearing) {
Rect bounds = canvas.getClipBounds();
// usual result: bottom=98, left=10, right=90, top=18
// draw something custom here...
// Don't want default compass image:
//super.drawCompass(canvas, bearing);
}
如何设置自定义图像的边界,以便对drawCompass的调用在画布对象上设置所需的边界?看来我得到的界限是适用于默认图像的界限。
(drawCompass 似乎是从 MyLocationOverlay.draw() 调用的 - 我可以覆盖它,但仍然不确定如何更改画布对象上的 ClipBounds。)
I am looking to draw my own compass image on a MapView by subclassing MyLocationOverlay. The custom image needs to be larger than the default image shown by MyLocationOverlay. I override drawCompass and use my own drawables (bitmaps) to draw the compass:
@Override
protected void drawCompass(Canvas canvas, float bearing) {
Rect bounds = canvas.getClipBounds();
// usual result: bottom=98, left=10, right=90, top=18
// draw something custom here...
// Don't want default compass image:
//super.drawCompass(canvas, bearing);
}
How do you set the bounds of the custom imagery so that calls to drawCompass set the required bounds on the canvas object? It seems the bounds I'm getting are those applicable to the default imagery.
(drawCompass appears to be called from MyLocationOverlay.draw() - I can override that, but am still unsure how to change the ClipBounds on the canvas object.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题让我意识到你描述的裁剪问题导致了我的自定义指南针绘制的奇怪方式。我在这里找到了答案:
http://jtomlinson.blogspot.com/2008/10/clipping .html
您需要使用
(要使用它,您需要
导入 android.graphics.Region。
)Your question made me realize the clipping problem you describe was causing the weird way my custom compass was drawing. I found the answer here:
http://jtomlinson.blogspot.com/2008/10/clipping.html
You need to use
(To use it you will need to
import android.graphics.Region.
)