【发布时间】:2012-10-25 10:16:04
【问题描述】:
我想制作一个 Android 应用,您可以在其中看到荷兰地图的图像,您可以在其中选择一个省份。 每个省都必须上另一个班。
我发现最好的方法是使用 2 张图片,其中 1 张是您展示的,另一张完全相同,但有颜色。比使用 touchEvent 获取颜色,然后说它的红色是否去上课。
到目前为止,我有 2 张图片,一张是我展示的,另一张是我展示的(完全相同,但每个省都有另一种颜色),这张图片我设置为“不可见”。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#ffffff" >
<ImageView
android:id="@+id/img_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/nl_clickable_original" />
<ImageView
android:id="@+id/img_hitbox"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/nl_clickable"
android:visibility="invisible" />
</FrameLayout>
但现在我不知道如何走得更远。
我在 StackOverflow 上找到了一些应该从图像中获取颜色的代码,但我不知道如何实现它。
private int getColour(int x, int y) {
ImageView img = (ImageView) findViewById(R.id.img_hitbox);
img.setDrawingCacheEnabled(true);
Bitmap hotspots = Bitmap.createBitmap(img.getDrawingCache());
img.setDrawingCacheEnabled(false);
return hotspots.getPixel(x, y);
}
这是正确的方法还是有人知道如何制作这个?
我现在已经搜索了 1 周,所以有点帮助会很好:)!
谢谢
【问题讨论】:
标签: android image map clickable areas