Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically load an AnimationDrawable in a TextView
    primarykey
    data
    text
    <p>I need to replace phrases of text in a with images and then append that to a TextView. For regular Drawables this is no problem, but when the Drawable is an AnimationDrawable I don't know where and when to call <code>.start();</code>.</p> <p>This is how I append text to the TextView:</p> <pre><code>textview.append(Html.fromHtml(textWithHtmlImgTags, imagegetter, null)); </code></pre> <p>The image tags in the textWithHtmlImgTags are replaced using imagegetter:</p> <pre><code>new ImageGetter() { @Override public Drawable getDrawable(String source) { if(source.endsWith("_ani")) { Log.i("cmv", "This is an animated drawable."); AnimationDrawable dra = (AnimationDrawable)res.getDrawable(sRes.get(source)); dra.setBounds(0, 0, dra.getIntrinsicWidth(), dra.getIntrinsicHeight()); dra.start(); // This doesn't work.. return dra; } Drawable dr = res.getDrawable(sRes.get(source)); dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight()); return dr; } }; </code></pre> <p>My AnimationDrawables are added, but they aren't animated (they're stuck on frame 1).</p> <p>In the documentation it says:</p> <blockquote> <p>It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus.</p> </blockquote> <p>Since the images are added dynamically I don't think it has anything to do with onCreate(). So I guess I call my <code>.start()</code> when my drawable <code>is not yet fully attached to the window</code>, but where/when/how <strong>should</strong> I call it?</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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