如何使用自定义指南针图像android

发布于 2024-11-29 21:28:00 字数 394 浏览 1 评论 0原文

首先我要说的是我看到了这个帖子: 如何我替换了 MyLocationOverlay 的指南针图像?

根据该线程,它告诉我无法覆盖该图标。

没什么大不了的。也就是说,我正在尝试找出一种方法来实现这一点。

我是否正确地说,我需要创建自己的自定义画布,该画布将简单地绘制图标并旋转它并覆盖另一个扩展 MyLocationOverlay 的自定义类中的 drawcompass 方法?

如果这是正确的,我如何创建图标的自定义画布/旋转它? (我没有在android操作系统中绘图的经验)。

Let me start by saying that I have seen this thread: How can I replace the Compass image of MyLocationOverlay?

According to that thread, it tells me that I can't override the icon.

Not a big deal. That said, I'm trying to figure out a way to implement this.

Would I be correct in saying that I would need to create my own custom canvas that would simply draw the icon and rotate it and override the drawcompass method in another custom class that extends MyLocationOverlay?

If that is correct, how do I create this custom canvas of the icon/rotate it? (I have no experience with drawing in the android os).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2024-12-06 21:28:00

不需要制作自己的自定义画布,只需重写 drawCompass 方法,因此看来我链接的初始问题中的信息不正确:

@Override
protected void drawCompass(Canvas canvas, float bearing) {

    Bitmap arrowBitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.compass);
      Matrix matrix = new Matrix();
        matrix.postRotate(bearing);
        Bitmap rotatedBmp = Bitmap.createBitmap(
            arrowBitmap, 
            0, 0, 
            arrowBitmap.getWidth(), 
            arrowBitmap.getHeight(), 
            matrix, 
            true
        );

        canvas.drawBitmap(rotatedBmp, 20, 20, null );
}

Didn't need to make my own custom canvas, only had to override the drawCompass method, so it appears that the information in the initial question I linked was incorrect:

@Override
protected void drawCompass(Canvas canvas, float bearing) {

    Bitmap arrowBitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.compass);
      Matrix matrix = new Matrix();
        matrix.postRotate(bearing);
        Bitmap rotatedBmp = Bitmap.createBitmap(
            arrowBitmap, 
            0, 0, 
            arrowBitmap.getWidth(), 
            arrowBitmap.getHeight(), 
            matrix, 
            true
        );

        canvas.drawBitmap(rotatedBmp, 20, 20, null );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文