Use of Android--animations (ii)

Source: Internet
Author: User

Animations's second method of using XML

The code is written in the Java file.

Advantages: Beginners Looking comfortable, code debugging are very convenient, breakpoints.

Disadvantage: The reusability of the code is too low . Object-oriented ultimate goal: reduce duplication of code .

The code is written in the XML file.

Pros: A and B controls can use an animated effect at the same time, improving reusability.   the maintainability is getting higher . For example, the boss says: The ramp effect becomes smaller

Cons: Code syntax can be checked by the compiler, and debugging is laborious.

Steps for using animations tweenedanimations in XML form

1. Create a new folder named anim below the Res folder

2, create the XML file under the folder, and first add the set tag , the Label property is set as follows: Set represents the collection, a series of admations

     <xmlns:android= "http://schemas.android.com/apk/res/android"     Android : interpolator= "@android: Anim/accelerate_interpolator"     android:shareinterpolator = "true" >     </ Set >

3. add rotate, alpha, scale, or translate tags to the set tag

4, use animation Utils in code(usually Utils end of the class contains some static functions, tool methods) to load the XML file, and generate animation object

1. Alpha animation in the form of XML
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/accelerate_interpolator">    <AlphaAndroid:fromalpha= "1.0"Android:toalpha= "0.0"Android:startoffset= "$"android:duration= "$">            </Alpha></Set>

2. Triggering in Java

Use Animationutils to mount the animation settings file.

Imageview.startanimation (animation);

    Private class Implements view.onclicklistener{        @Override        publicvoid  OnClick (View v) {            = Animationutils. loadanimation (Mainactivity.  This , R.anim.alpha);            Imageview.startanimation (animation);        }    }

The previous execution of Animationset.addanimation () then executes the Admationset object.

How do you directly execute the animation object here?

First Startanimation (animation) accepts the parameter is the animation type, why the last wear animationset also no problem, because Animationset is the subclass of animation, upward transformation .

1, rotate animation in the form of XML
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/accelerate_interpolator">       <Rotateandroid:fromdegrees= "0"android:todegrees= "+350"Android:pivotx= "50%"Android:pivoty= "50%"android:duration= " the">            </Rotate></Set>

Three types of Pivox y:

    1. android:pivotx= "50" using absolute position positioning
    2. Android:pivotx= "50%" is positioned relative to the control itself
    3. android:pivotx= "50%p" relative to the control's parent control positioning
    <Translate
Android:fromxdelta= "50%" Android:toxdelta= "70% "Android:fromydelta= "0%" Android:toydelta= "80% "Android:duration= " the"/> < ScaleAndroid:fromxscale= "1.0"Android:toxscale= "0.0" android:fromyscale= "1.0 "Android:toyscale= "0.0"Android:pivotx= "50%" android:pivoty= "50% "Android:duration= " the"/>

Use of Android--animations (ii)

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.