Android Properties Animation (i)

Source: Internet
Author: User

I. Overview

There are two main types of animations used in Android platforms, one is view animation, and the other is a new property animation after 3.0. Property animations are more powerful than view animations and are mainly reflected in the following two areas:

1, attribute animation can not only be applied to the view, but also can be applied to object objects.

2. Property animation will really change the value of the object property.

With such a powerful animation, there's no reason not to learn to use it, let's start with the API documentation to learn how to use property animations.

Learning and using of attribute animation

First we need to understand some of the key properties of property animations, which are given in the documentation:

Duration: This is a good understanding of the duration of the animation.

Time Interpolation: Time difference, mainly used to define the rate of change in the animation, the system has provided a number of well-defined interpolator, in particular, the following table can be referred to:

Repeat count and behavior: number of repetitions and patterns that define how many times the animation repeats and how it repeats.

Animator sets: A collection of animations for composing animations that specify the order in which animations are executed.

Frame Refresh delay: brush frame delay.

Having understood the meaning of these attributes, we are looking at the classes related to property animation, and we can see from the table that there are 3 main ones, namely Valueanimator, Objectanimator, Animatorset, Where Objectanimator is a subclass of Valueanimator.

Most of the cases we use Objectanimator can be easily completed very good animation, let us first experience. First the layout file, very simple, only one picture and a button.

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >    <ImageViewAndroid:layout_width= "100DP"Android:layout_height= "100DP"Android:id= "@+id/imageview"Android:scaletype= "Fitxy"android:src= "@drawable/animator_img"android:contentdescription= "@null"/>    <ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/btnok"Android:text= "OK"Android:layout_alignparentbottom= "true"/></Relativelayout>

  Java:

        Findviewbyid (R.id.btnok). Setonclicklistener (new  Onclicklistener () {            @Override              publicvoid  OnClick (View v) {                objectanimator                    "Translationx", 0f,300f)                    . Setduration (+)                    . Start ();            }        );

As follows:

Through the above demonstration, we can see that using Objectanimator can be very convenient to complete an animation, just a line of code, while through the toast we can see that the location of the image of the property is indeed changed.

We specifically understand that Objectanimator,objectanimator provides Ofint, Offloat, Ofobject and other methods, which basically need the following parameters:

Object target: The target object that the animation is acting on.

String PropertyName: The Action property of the animation, note that the target object must provide a Get/set method for this property.

Float/int. Values: A variable parameter that defines the start, middle, and end values of an animation.

By default, the animation change effect is linear, and we can set an interpolator to change the animation's rate of change by using the Setinterpolator method.

Animatorset: For combining animations, here's an example of how this is done, with the main code as follows:

Animatorset Animatorset =NewAnimatorset (); Objectanimator Animator1= Objectanimator.offloat (ImageView, "X", 0,screenwidth-imgwidth); Animator1.setduration (2000); Animator1.setinterpolator (Newdecelerateinterpolator ()); Objectanimator Animator2= Objectanimator.offloat (ImageView, "Y", 0,screenheight-imgheight); Animator2.setduration (2000); Animator2.setinterpolator (Newaccelerateinterpolator ()); Objectanimator Animator3= Objectanimator.offloat (ImageView, "X", screenwidth-imgwidth,0); Animator3.setduration (2000); Animator3.setinterpolator (Newaccelerateinterpolator ()); Objectanimator Animator4= Objectanimator.offloat (ImageView, "Y", screenheight-imgheight,0); Animator4.setduration (2000); Animator4.setinterpolator (Newaccelerateinterpolator ());            Animatorset.play (Animator1);            Animatorset.play (Animator2). After (Animator1);            Animatorset.play (Animator3). After (Animator2);            Animatorset.play (ANIMATOR4). After (Animator3); Animatorset.start ();

Through the above code, we can see through the animatorset, we can any combination of animation, and arrange their execution order, the picture in the screen in a clockwise direction for a week, and because the use of the interpolator, its change rate is different, the implementation of the effect is as follows:

Do you understand me? To test the small partner, you can click the download Project to run the test directly! If you have any questions, you can talk about it.

Android Properties Animation (i)

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.