“隐藏” Android 中的 OverlayItem 可能吗?
我正在开发一个 MapView 应用程序,并且想在程序中放置一个漂亮的小复活节彩蛋。我想做的是有一个基本上不可见的覆盖项目,但点击时会触发一个事件来显示视图。
现在在 iPhone 上,我通过在我不希望可见的注释上使用 setHidden:true 来完成此操作。注释仍然存在并且仍然可单击,但您看不到它。
我试图在Android中的overlayItem上找到一些等效的方法,但什么也没找到。我唯一的选择是接受此操作来查找/创建透明图像并将其作为叠加层添加到地图视图吗?如果有必要的话我可以这样做,但是还有其他选择吗?如果没有,谁能给我指出一个相对较小的透明图像?
I am working on a MapView app, and would like to place a nice little easter egg in the program. What I am trying to do is have an overlayitem that is basically invisible, but when tapped will trigger an event to show a view.
Now on the iPhone i accomplished this by using setHidden:true on the annotation I didn't want visible.. the annotation was still there and still was clickable, but you could not see it.
I am trying to find some equivalent method on the overlayItem in Android, but find nothing. Is my only option to accopmlish this to find/create a transparent image and add it as an overlay to the mapView? I can do this if I have to, but are there any other options? And if not can anyone point me to a relatively small transparent image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道您找到了一种隐藏叠加层的方法,但还有更优雅的方法来做到这一点。
为您的覆盖层创建一个自定义类:
然后在您的活动中,照常添加覆盖层:
稍后,如果您想显示/隐藏您的覆盖层,只需调用:
或:
希望它有帮助。
I know you found a way to hide your overlay but there is more elegant way to do this.
Make a custom class of your overlay:
Then in your activity, add overlays as usual:
Later, if you want to show/hide your overlay, simply call:
or:
Hope it helps.
您可以在地图视图顶部制作一个可点击的图像视图(相应地设置宽度/高度并将颜色设置为透明),单击该图像视图时会触发复活节彩蛋。然而,正确定位它可能很困难。
除此之外,我可以想象使用自定义视图,如果 x,y 坐标在一个盒子内,您可以重写 onTouch 函数来触发复活节彩蛋..否则它会被处理地图视图。但这听起来对于复活节彩蛋来说可能需要做很多工作。
You can make a clickable imageview (set the width/height accordingly and the color to be transparent) on top of your map view, which when clicked, triggers the easter egg. However it might be difficult to position it correctly..
Aside from that, I can imagine using a custom view where you override the onTouch function to trigger the easter egg if x,y coordinates are within a box.. and it otherwise gets processed by the map view. But this sounds like it could be a lot of work for an easter egg..
我发现最简单的解决方案是仅使用不可见的可绘制对象并将其添加为覆盖项,所以这就是我所做的并且它按预期工作。
I found the easiest solution was to just use an invisible drawable and add it as an overlayitem, so this is what I did and it works as expected.