snipt

Ctrl+h for KB shortcuts

Java

Waiting for an animation to finish or do a sequence of animations

anim = AnimationUtils.loadAnimation(this, R.anim.MyAnimation);
anim.setAnimationListener(new AnimationListener() {
	public void onAnimationStart(Animation animation) {
	}
	public void onAnimationRepeat(Animation animation) {
	}
	public void onAnimationEnd(Animation animation) {
		//Do something or start a new animation
	}

});
((TextView) findViewById(R.id.lblText)).startAnimation(anim);
https://snippets.siftie.com/embed/b6eac2ab32d8144f8ce2b29c74e81037/
/raw/b6eac2ab32d8144f8ce2b29c74e81037/
b6eac2ab32d8144f8ce2b29c74e81037
java
Java
12
2019-03-20T00:46:56
True
False
False
/api/public/snipt/18321/
waiting-for-an-animation-to-finish-or-do-a-sequence-of-animations
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">anim</span> <span class="o">=</span> <span class="n">AnimationUtils</span><span class="o">.</span><span class="na">loadAnimation</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="n">R</span><span class="o">.</span><span class="na">anim</span><span class="o">.</span><span class="na">MyAnimation</span><span class="o">);</span> </span><span id="L-2"><a name="L-2"></a><span class="n">anim</span><span class="o">.</span><span class="na">setAnimationListener</span><span class="o">(</span><span class="k">new</span> <span class="n">AnimationListener</span><span class="o">()</span> <span class="o">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onAnimationStart</span><span class="o">(</span><span class="n">Animation</span> <span class="n">animation</span><span class="o">)</span> <span class="o">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="o">}</span> </span><span id="L-5"><a name="L-5"></a> <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onAnimationRepeat</span><span class="o">(</span><span class="n">Animation</span> <span class="n">animation</span><span class="o">)</span> <span class="o">{</span> </span><span id="L-6"><a name="L-6"></a> <span class="o">}</span> </span><span id="L-7"><a name="L-7"></a> <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onAnimationEnd</span><span class="o">(</span><span class="n">Animation</span> <span class="n">animation</span><span class="o">)</span> <span class="o">{</span> </span><span id="L-8"><a name="L-8"></a> <span class="c1">//Do something or start a new animation</span> </span><span id="L-9"><a name="L-9"></a> <span class="o">}</span> </span><span id="L-10"><a name="L-10"></a> </span><span id="L-11"><a name="L-11"></a><span class="o">});</span> </span><span id="L-12"><a name="L-12"></a><span class="o">((</span><span class="n">TextView</span><span class="o">)</span> <span class="n">findViewById</span><span class="o">(</span><span class="n">R</span><span class="o">.</span><span class="na">id</span><span class="o">.</span><span class="na">lblText</span><span class="o">)).</span><span class="na">startAnimation</span><span class="o">(</span><span class="n">anim</span><span class="o">);</span> </span></pre></div> </td></tr></table>
android