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

查看:173
本文介绍了如何在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.

>

推荐答案

一种方法是使用canvas。

One way to do this would be to use canvas.

@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天全站免登陆