Animationutil animation tool class

Source: Internet
Author: User

Simple hands-on program

Code on

Package mars.com; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. view. animation. animation; import android. view. animation. animationutils; import android. widget. button; import android. widget. imageview; public class demo_activity extends activity {private button button1; private button button2; private imageview image; private animation loadanimation; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); button1 = (button) findviewbyid (R. id. button1); button2 = (button) findviewbyid (R. id. button2); image = (imageview) findviewbyid (R. id. image); // The following is the listener button1.setonclicklistener (New onclicklistener () {public void onclick (view v) {loadanimation = animationutils. loadanimation (getapplicationcontext (), R. anim. anim); image. setanimation (loadanimation); // sets the animation loadanimation for the control. setfillafter (true); // stay until the end of loadanimation. setfillenabled (true); // loadanimation. startnow (); // start animation}); button2.setonclicklistener (New onclicklistener () {public void onclick (view v) {loadanimation. cancel (); // cancel the animation }});}}

The main. XML Code is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <button Android: id = "@ + ID/button1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "Start Animation"/> <button Android: id = "@ + ID/button2" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "Stop Animation"/> <imageview Android: id = "@ + ID/image" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/ic_launcher"/> </linearlayout>

The configuration file anim. anim. XML is as follows:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="3000"        android:toXDelta="0"        android:toYDelta="300" />    <rotate        android:duration="3000"        android:fromDegrees="270"        android:pivotX="50%"        android:pivotY="50%"        android:toDegrees="360" /></set>

The running effect is as follows:

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.