Animated animation of wirelessly (1)

Source: Internet
Author: User

Attribute Animation (property aniamtion) is a new animation launched in Google.

1. What is an attribute animation?

Property animation, as the name implies, is the animation of manipulating properties. Here may be someone to ask what is the property of the operation? Think of the animation we learned before--transform animation, you can change the animation display of the various patterns, look very cool, layout animation, you can change the activity to jump your animation, frame animation, Flash animation is the same. When we use these animations, especially when transforming the animation, have you ever thought, if a imageview has a listener event, and we use the transform animation to replace the ImageView position, at this time we want to implement this ImageView, where to click?  Is it the original position, or is it the current position? After the experiment, it was found that only the original position was clicked to respond, why? This is the downside of the transform animation, which, although it can animate the view, does not change the properties of the view itself, which results in the user being very uncomfortable in the application, because the user does not know these things at all. Instead, the property can achieve the effect of adding an animation to the view while also changing the view's properties, which is known as the property animation

2. Why use attribute animation?

Transforming animations can add some cool effects to the view, which is beyond doubt. But in the user interaction, it dwarfs, after all, the transformation animation is only for the user to see, if you want to use the transformation animation to interact is far from. Property animation, is to fill this vacancy for the transformation animation. If you want to achieve effects and interactions, use property animations, and if you only need effects, use transform animations.

3. How to use property animations

First of all, we know that ordinary animation is called animation, while property animation is animator. Literally, we can understand that animation is an ordinary animation, and animator is the person who operates the animation, it wantonly change the animation of various things, including loading animation view of related things. For example, ImageView is the computer, animation is the operating system, animator is the user, when the computer does not have no system, we can also use it, such as into the BIOS and so on, when the computer installed on the operating system, that is, ImageView loaded animation, We can use the computer more features, but this is only limited to the operating system, such as the operating system can not modify certain parameters of the computer, and users are different, you can operate the computer, the use of functions, but also can change the parameters of the computer. This is the role of property animation.

Second, let's take a look at the API that Android officially provides. Animator is an animated parent of all properties, inheriting it with Animatorset (animated collection), Valueanimator. We usually use valueanimation and its subclass Objectanimator. I only say objectanimator use, valueanimation in the next time.

Now let's look at the code

Layout file Code

XML code

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context= "Com.example.android_propertyaniamtion." Mainactivity " >6 7     <ImageView8         Android:id= "@+id/imageview"9 Android:layout_width= "Wrap_content"Ten Android:layout_height= "Wrap_content" One Android:layout_alignparenttop= "true" A android:src= "@drawable/ic_launcher" /> -  -     <Button the         Android:id= "@+id/button" - Android:layout_width= "Fill_parent" - Android:layout_height= "Wrap_content" - Android:layout_alignparentbottom= "true" + Android:text= "@string/button_string" /> -  + </Relativelayout>

Activity Code

Java code

1  Packagecom.example.android_propertyaniamtion;2 3 ImportAndroid.animation.ObjectAnimator;4 Importandroid.app.Activity;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.View;7 ImportAndroid.view.View.OnClickListener;8 ImportAndroid.widget.Button;9 ImportAndroid.widget.ImageView;Ten  One  Public classMainactivityextendsActivityImplementsonclicklistener{ A     PrivateButton Button =NULL; -     PrivateImageView ImageView =NULL; -      the     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -button =(Button) Findviewbyid (R.id.button); +ImageView =(ImageView) Findviewbyid (R.id.imageview); -Button.setonclicklistener ( This); +Imageview.setonclicklistener ( This); A     } at  -      Public voidOnClick (View v) { -         Switch(V.getid ()) -         { -              CaseR.id.button: -             { in //float Fromxdelta = Imageview.getx (); - //float Fromydelta = imageview.gety (); to //translateanimation animation = new Translateanimation (Fromxdelta, Fromxdelta + $, Fromydelta, Fromyd ELTA); + //Animation.setfillafter (true); - //animation.setduration (+); the //imageview.startanimation (animation); *                 //here, the factory method is used to create a Objectanimator object. $                 /*Panax Notoginseng * First parameter: The view to which the animation needs to be loaded - * Second parameter: Operation command (Translationy-operation on y-axis, translationx--operation on X-axis) the * Third parameter: the original coordinate of the symmetric axis to be manipulated + * Fourth parameter: Post-operation coordinates A                  */ theObjectanimator OA = objectanimator.offloat (ImageView, "Translationy", 0F, 100F); +Oa.setduration (1000); - Oa.start (); $                  Break; $             } -              CaseR.id.imageview: -             { the                  Break; -             }Wuyi         } the     } -      Wu}

Animated animation of wirelessly (1)

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.