OnCameraChangeListener is not responsive enough - is there another way?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 06:25:03

问题


I am porting a layer I have in a v1 map to v2. The layer draws a custom control on the map and, as the map moves, it must stay in place on its current geolocation (w/ the correct scale).

It had been suggested to me to use onCameraChange to communicate to my layer (a custom view, on top of the map) that the camera was panning or zooming and update the layer appropriately.

My problem is that onCameraChange is only called after the camera has been moved - not during. It is therefor not responsive enough. Is there another way to achieve this?


回答1:


Try to wrap the MapFragment (or MapView) inside your custom class inherited from something like RelativeLayout. Then you can override onInterceptTouchEvent or dispatchTouchEvent in that custom layout and move your custom view from there. I tried it myself and it will give you definitely more callbacks than with the onCameraChange.

You can also take a look at my answer here:
Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)
I was dealing with something little bit different (I tried to avoid moving custom views over the map but I needed only some buttons on an infoWindow), but I used this wrapping layout there too.



来源:https://stackoverflow.com/questions/14235686/oncamerachangelistener-is-not-responsive-enough-is-there-another-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!