如何在android中的图像上放置图钉标记图像? [英] How to place pin mark image over an image in android?

查看:35
本文介绍了如何在android中的图像上放置图钉标记图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 新手.我正在开发一个项目,我将在其中获取无线电信号值(我可以从 API 获取值).我有一个平面图.平面图有厨房、大厅、卧室部分.如果我点击厨房部分,我需要在该部分放置一个带有无线电信号值的 Pin 图像.单击保存"后,我需要锁定该特定部分中的图像(带有值).同样,我可以根据需要放置许多 Pin 图像.

I am new to Android. I am developing a project where I will get the Radio signal values(I can get the values from API). I have a floor plan. The floor plan has kitchen,hall,bedroom sections.. If I click the Kitchen section, I need to place an Pin Image in that section with Radio signal values. Once I click Save, I need to lock the Image(with values) in that particular section. Similarly I can place many Pin images based on the requirement.

请给我一些相关的链接或示例代码来开发这个.我附上了图片供您参考.任何帮助将非常感激.

Please give me some related link or sample codes to develop this. I have attached the Image for your reference. Any help would be really appreciated.

推荐答案

一种方法是使用画布.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Bitmap map = BitmapFactory.decodeResource(getResources(), R.drawable.map);
    canvas.drawBitmap(map, xPositionForMap, yPositionForMap, null);

    Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
    canvas.drawBitmap(marker, xPositionFor1stMarker, yPositionFor1stMarker, null);
    canvas.drawBitmap(marker, xPositionFor2ndMarker, yPositionFor2ndMarker, null);
}

稍后在 onDraw 中绘制的内容出现在先前绘制的内容之上.可能 BitmapFactory.decodeResource 应该在 create/init mat hod 中,因此不会在每次调用 onDraw 时调用它们.请参阅 http://developer.android.com/training/custom-views/custom-drawing.html 了解更多信息.

Things drawn later in the onDraw appear on top of those drawn earlier. Probably the BitmapFactory.decodeResource should be in a create/init mat hod so they aren't called every time onDraw is called. See http://developer.android.com/training/custom-views/custom-drawing.html for more information.

对于点击图钉,您会捕捉到对包含画布的布局的点击,并有条件地添加额外的可绘制对象和文本.

For clicking on the pins you would catch clicks on the Layout containing the canvas and conditionally add extra drawables and text.

另一种方法是使用RelativeLayout并放置ImageView,其工作方式类似.

An alternative way is to use RelativeLayout and put ImageView, which would work similarly.

这篇关于如何在android中的图像上放置图钉标记图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆