首先,真的很抱歉迟到的答案。希望对大家来说还不算太晚:)
我用代码示例(不是工作应用程序)制作了一个 GitHub 存储库,所以请使用它!:)
使用 repo 的自述文件了解一些细节。
核心解决方案:
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.world_map);
// Get image view (this is our SVG map that is going to be clickable and zoomable):
ImageView touchImageView = (ImageView) view.findViewById(R.id.touchImageView);
// Create drawable (will convert svg to drawable so we can set it to image view as a bitmap):
PictureDrawable image = svg.createPictureDrawable();
Bitmap b = drawableToBitmap(image); // refer to WorldMapFragment for source code of the converting method
touchImageView.setImageBitmap(b);
// Create image with clickable areas from previous image view and set listener to id (listener of type OnClickableAreaClickedListener created in onAttach callback):
ClickableAreasImage clickableAreasImage = new ClickableAreasImage(new PhotoViewAttacher(touchImageView), listener);
// Define your clickable areas
// parameter values (pixels): (x coordinate, y coordinate, width, h eight) and assign an object to it
List<ClickableArea> clickableAreas = new ArrayList<>();
Map<String, FintemCity> cities = svg.getCities();
for (String key : cities.keySet()){
clickableAreas.add(cities.get(key).toClickableArea(getMetrics()));
}
// Set your clickable areas to the image
clickableAreasImage.setClickableAreas(clickableAreas);
投票表示赞赏!:)