在 MapView 中的地图标记上方显示弹出窗口 [英] Show popup above map marker in MapView

查看:40
本文介绍了在 MapView 中的地图标记上方显示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不敢相信没有简单的方法可以做这样一个基本的事情......我想在用户点击地图标记(类似于谷歌的东西)后显示一个弹出窗口/气球(一个线性布局)地图应用程序).当用户滚动地图时,它应该随地图移动.这样做的最佳方法是什么?

I can't beleive there's no easy way to do such a basic thing like this... I want to show a popup/baloon (a LinearLayout) after user clicks on a map marker (something smilar to what is in Google Maps app). It should move with the map, when the user scrolls the map. What is the best way to do this?

一个想法是在我的 Activity 的根布局中使用 LinearLayout 并在需要时显示它.但是如何让它随地图移动?

One idea is to have the LinearLayout in my Activity's root layout and show it when needed. But how to make it move with the map?

另一种方法可能是创建一个 Overlay,在 onDraw 中绘制 LinearLayout 并提供布局触摸事件.这可能吗?

Another way to do that may be to create an Overlay that draws the LinearLayout in onDraw and gives the layout touch events. Is this possible?

推荐答案

我的做法是:

http 中所述,通过子类化ItemizedOverlay 将标记放置在所需的GeoPoints://developer.android.com/guide/tutorials/views/hello-mapview.html

通过从布局中膨胀来创建一个弹出式视图:

Create a popup View by inflating from the layout:

View popUp = getLayoutInflater().inflate(R.layout.map_popup, map, false);

使用 MapView.LayoutParams 相对于 ItemizedOverlay 中的 GeoPoint 定位弹出窗口::onTap 方法.当用户滚动地图时,弹出窗口将自动滚动(无需任何额外代码).基本上弹出窗口与 GeoPoint 相关联,如果用户缩放,弹出窗口的位置会自动调整.

Use MapView.LayoutParams to position the popup with respect to GeoPoint in the ItemizedOverlay< OverlayItem >::onTap method. Popup will scroll automatically (without any additional code) when user scrolls the map. Basically popup gets tied to a GeoPoint, if user zooms, popup's position gets adjusted automatically.

MapView map = (MapView) findViewById(R.id.mapview);   
MapView.LayoutParams mapParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        <geopoint>,
                        <x offset if required>,
                        <y offset like pinHeight>,
                        MapView.LayoutParams.BOTTOM_CENTER);
map.addView(popUp, mapParams);

这篇关于在 MapView 中的地图标记上方显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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