简体   繁体   中英

Animation on custom infowindow using google maps in Android

I'm trying to use customized marker "bubbles" in my Android app. To do this, I created a InfoWindowAdapter which returns and populates the View.

However, for some reason, it seems it won't let me apply an animation to that view (or whatever is inside). I would like it to pop in a certain, animated way but I'm probably missing something.

This is what I've tried so far:

map.setInfoWindowAdapter(new InfoWindowAdapter() {
    private final View contents = getLayoutInflater().inflate(R.layout.marker_layout, null);

    public View getInfoWindow(Marker marker) {
        TranslateAnimation animator = new TranslateAnimation(0.0f, 0.0f, 0.0f, 100.0f);

        animator.setDuration(2000);
        animator.setInterpolator(new AccelerateInterpolator());
        animator.setFillAfter(true);

        contents.findViewById(R.id.entity_name).clearAnimation();
        contents.findViewById(R.id.entity_name).startAnimation(animator);

        ((TextView) contents.findViewById(R.id.entity_name)).setText(marker.getTitle());
        return contents;
    }
/* ... */

The view gets succesfully created and populated, but no aparent animation. If I apply that same animation to another element of the layout it works flawlessly so I'm starting to think this is something about the way Google Maps uses the information windows, perhaps?

You can't apply animation to the InfoWindow , for one simple reason. what you see in the InfoWindow is not the layout you defined but an image that was drawn from it. meaning you can'y manipulate this InfoWindow .

From Google's documentation:

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas) ) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (eg, after an image has loaded), call showInfoWindow() . Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

You may try to work this limitation around by using Handler and Marker.showInfoWindow() .

For a short period of time, send messages to handler, call showInfoWindow and create different views (with different bottom margin in your case) every time in getInfoWindow.

This can be a bit tricky. You will have to keep track of opened info window to not continue "animation" when user closes it during these 2 seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM