Custom Animations for Android development

Source: Internet
Author: User
<span id="Label3"></p><p><p>Custom animations, you need to create a new class that inherits the animation class.</p></p><p><p>Override the Applytransformation () method and the Initialize () method.</p></p><p><p>Applytransformation (float interpolatedtime, Transformation T) method</p></p><p><p>First Parameter: Interpolatedtime represents the time of the Animation. This parameter always changes from 0 to 1, regardless of the actual duration of the animation, when the animation plays.</p></p><p><p>The second Parameter: transformation T represents the degree to which a tweened animation distorts a shape or component at different Times.</p></p><p><p></p></p><p><p>button to achieve left and right shaking effect</p></p><p><p>Custom animations</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Customanim<span style="color: #0000ff;"><span style="color: #0000ff;">extends</span></span><span style="color: #000000;"><span style="color: #000000;">Animation {</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>Initialize<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>Width<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>Height<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">parentwidth,</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span><span style="color: #000000;"><span style="color: #000000;">Parentheight) {</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. Initialize (width, height, parentwidth, parentheight);</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">protected</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>Applytransformation (<span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span><span style="color: #000000;"><span style="color: #000000;">interpolatedtime, Transformation T) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span>T.getmatrix (). settranslate ((<span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span>) Math.sin (interpolatedtime*50) *50,0<span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. applytransformation (interpolatedtime, t);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span>}</pre><p><p>button click Effect Settings in Mainactivity</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Mainactivity<span style="color: #0000ff;"><span style="color: #0000ff;">extends</span></span><span style="color: #000000;"><span style="color: #000000;">Activity {</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span><span style="color: #000000;"><span style="color: #000000;">Customanim ca;</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">protected</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onCreate (Bundle Savedinstancestate) {</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. OnCreate (savedinstancestate);</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #000000;"><span style="color: #000000;">Setcontentview (r.layout.activity_main);</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #008080;"><span style="color: #008080;">Ten</span></span>Ca=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Customanim ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span>Ca.setduration (1000<span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span>Findviewbyid (r.id.btnanimationme). Setonclicklistener (<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Onclicklistener () {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">OnClick (View V) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">TODO auto-generated Method Stub</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">v.setanimation (ca);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> });</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>}</pre><p><p></p></p><p><p>Custom Animations for Android development</p></p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.