问题
As we know in google maps android version 2, a custom information windows, is a view that converts to an image. Actually google aftre you return you view converts the view to a image an then show it to the info windows.
But I want to show images downloading from internet to my infowindow. Actually, I want that before that download complete show an progress bar to my infowindows and after it compeleted update info windows, by this mechanism how I can do this?
回答1:
- Have a model object that contains int for progress and Bitmap for actual image.
- Start some kind of background operation started (e.g. AsyncTask) to download image.
- Update model's progress from
AsyncTask.onProgressUpdate
. - Update model's image from
AsyncTask.onPostExecute
. - Have an observer for model (see Observer partern).
- If you keep
AsyncTask
(or any other kind ofThread
inActivity
context, don't forget tocancel
it and you may also skip observer pattern. - Save reference to marker showing info window inside
InfoWindowAdapter.getInfoWindow
. Call itmarkerShowingInfoWindow
. - When you are notified of progress update,
call:
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) {
markerShowingInfoWindow.showInfoWindow();
}
To force InfoWindowAdapter.getInfoWindow
call and create ViewGroup
containing ProgressBar
and ImageView
from progress and image values inside model.
As always, translate this into C# world.
来源:https://stackoverflow.com/questions/17131039/google-maps-version-2-updating-information-windows