Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I use AnimationDrawable in an overlay on a MapView?
    primarykey
    data
    text
    <p>I have created an AnimationDrawable in XML, and it works fine. But on moving the drawable into a MapView as an overlay marker (replacing a static drawable that works fine), the animation stubbornly refuses to play. I've moved the call to start() to a button, for testing, and even when pressed several seconds after the MapView has displayed, the animation doesn't start. I'm seeing nothing in logcat. I know start() needs calling after all the windows are set up, but this seems to be a separate issue.</p> <p>Are AnimationDrawables compatible with MapView?</p> <p>Is there something special I need to do to make one work in a MapView?</p> <p>Have you ever successfully had one work in a MapView?</p> <h2>Solution</h2> <p>Using Matt's solution (below) I added the AnimationDrawable by putting the ImageView inside the MapView's layers, rather than using an overlay.</p> <pre><code>public void showAnimatedMarker(GeoPoint point) { LinearLayout v = (LinearLayout) View.inflate(context, R.layout.markerlayout, null); ImageView marker = (ImageView) v.findViewById(R.id.marker); AnimationDrawable markerImage = (AnimationDrawable)marker.getDrawable(); this.addView(v, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER)); markerImage.start(); } </code></pre> <p>And then markerlayout.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/marker" android:src="@drawable/my_animation_drawable" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload