Android的:如何使每个国家产生不同的动作可点击地图上的形象?图上、形象、不同、动作

2023-09-11 20:18:17 作者:抬头抚摸那一抹阳光 */

我需要显示欧洲地图的pretty的形象,我想,如我的应用程序调出不同的活性,当用户点击每个国家。 - 每一个国家在地图上需要有一个不同onClickListener(或等同物)

I need to display a pretty image of a map of Europe, and I want my app to, e.g. bring up a different activity, when the user clicks each country - each country on the map needs to have a different onClickListener (or equivalent).

从本质上讲,我需要能够在用户的图像,例如这个,而不是西班牙水龙头法国调用不同的功能: http://commons.wikimedia.org/wiki/File:Blank_map_of_Europe_cropped.svg

Essentially, I need to be able to call a different function when the user taps on France rather than Spain in an image such as this: http://commons.wikimedia.org/wiki/File:Blank_map_of_Europe_cropped.svg

我如何能最好地去了解这个在Android?

How would I best go about this on Android?

我有想法,但也有可能是我俯瞰一些简单的方法。

I've got ideas, but there may be some simple way that I'm overlooking.

提前感谢!

干杯, r3mo

推荐答案

下面是我如何解决类似的问题。

Here is how I solved a similar problem.

首先复制要作为图像映射使用和颜色各部分的图像。不用说,不同的颜色为每个部分:D。然后创建你的布局2 ImageViews。设置第一个作为要显示到屏幕上的图像和第二背景作为着色之一的背景。

First duplicate the image that you want to use as an image map and colour each section. Needless to say, a different colour for each section :D. Then create two ImageViews in your layout. Set the background of the first one as the image that you want displayed to screen and the background of the second as the coloured in one.

然后设置第二ImageView的不可见的可见性。如果你在这一点上运行的程序,你应该可以看到你想要显示的图像。然后使用OnTouch监听器,并得到你感动的像素的颜色。颜色将对应于该彩色图像的

Then set the visibility of the second ImageView to invisible. If you run the program at this point you should see the image that you want displayed. Then use an OnTouch listener and get the colour of the pixel where you touched. The colour will correspond to that of the coloured image.

下面getColour方法将需要传递的触摸事件的X和Y坐标。 R.id.img2是不可见的图像。

The following getColour method would need to be passed the x and y coordinates of the touch event. R.id.img2 is the invisible image.

private int getColour( int x, int y)
{
    ImageView img = (ImageView) findViewById(R.id.img2);
    img.setDrawingCacheEnabled(true); 
    Bitmap hotspots=Bitmap.createBitmap(img.getDrawingCache()); 
    img.setDrawingCacheEnabled(false);
    return hotspots.getPixel(x, y);
}

希望这是对你有所帮助:)

Hope this was of some help to you :).