snipt

Ctrl+h for KB shortcuts

Java

Simple animation of View (control)

//1. add the animation to your code
TextView lblValue= (TextView)findViewById(R.id.lblMainVal);
if(lblValue!=null){
	Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
	lblValue.startAnimation(myFadeInAnimation);		
}

//2. Create a "fadein.xml" file in the "res/anim" folder with this source
/*
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" />
*/
https://snipt.net/embed/99ec49cd4526e013556c5aa10b4aa357/
/raw/99ec49cd4526e013556c5aa10b4aa357/
99ec49cd4526e013556c5aa10b4aa357
java
Java
14
2019-05-25T08:51:04
True
False
False
/api/public/snipt/17963/
simple-animation-of-view-control
<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> <a href="#L-13">13</a> <a href="#L-14">14</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//1. add the animation to your code</span> </span><span id="L-2"><a name="L-2"></a><span class="n">TextView</span> <span class="n">lblValue</span><span class="o">=</span> <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">lblMainVal</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span><span class="o">(</span><span class="n">lblValue</span><span class="o">!=</span><span class="kc">null</span><span class="o">){</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">Animation</span> <span class="n">myFadeInAnimation</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">fadein</span><span class="o">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">lblValue</span><span class="o">.</span><span class="na">startAnimation</span><span class="o">(</span><span class="n">myFadeInAnimation</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><span id="L-8"><a name="L-8"></a><span class="c1">//2. Create a &quot;fadein.xml&quot; file in the &quot;res/anim&quot; folder with this source</span> </span><span id="L-9"><a name="L-9"></a><span class="cm">/*</span> </span><span id="L-10"><a name="L-10"></a><span class="cm">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span> </span><span id="L-11"><a name="L-11"></a><span class="cm">&lt;alpha xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span> </span><span id="L-12"><a name="L-12"></a><span class="cm"> android:interpolator=&quot;@android:anim/accelerate_interpolator&quot;</span> </span><span id="L-13"><a name="L-13"></a><span class="cm"> android:fromAlpha=&quot;0.0&quot; android:toAlpha=&quot;1.0&quot; android:duration=&quot;1000&quot; /&gt;</span> </span><span id="L-14"><a name="L-14"></a><span class="cm">*/</span> </span></pre></div> </td></tr></table>
android