Animated Animation (property Animation) (bottom)

Source: Internet
Author: User

Hello, everyone, I haven't written a blog for a long time, because I decided to quit my job.

Don't say much, we're still here. Property animation in the property Animation of the previous Android animation, we briefly introduced the use of property animation, in fact, property animation has more interesting usage.

1, using in XML

In Eclipse we right-click New XML to choose the new property animation.


We choose Objectanimator, and then we'll see a familiar scene.


Then we can use smart hints to see more familiar


Yes, we should know how to use XML layout to write property animations.

<span style= "FONT-SIZE:14PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><objectanimator xmlns:android= "http://schemas.android.com/apk/ Res/android "    android:duration=" "    android:propertyname=" Rotation "    android:valuefrom=" 0 "    android:valueto= "android:valuetype=" "    floattype"     ></objectAnimator></span>


protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( r.layout.activity_animation); button = (button) Findviewbyid (R.id.btn_anim); Button.setonclicklistener (new Onclicklistener () {@SuppressLint ("Newapi") @Overridepublic void OnClick (View v) {Animator Animator = Animatorinflater.loadanimator (Animationactivity.this, r.animator.animation); Animator.settarget (button); Animator.start ();}});}
effect

At the same time we can see that there is a set in the new XML, the use of set is also very simple

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:ordering= "sequentially" ><!--ordering= "Together" simultaneously play      ordering= "sequentially" sequence play--    <objectanimator/>    <objectanimator/></set>

2, layout animation

There is a transition animation effect when the view hierarchy in the container changes, so let's take a look at the effect of Apidemo first.


We can see that the button we added or the Remove button will have an animated effect when we tick in, and then we'll look at the code

Check for disabled animations        checkbox APPEARINGCB = (CheckBox) Findviewbyid (R.ID.APPEARINGCB);        Appearingcb.setoncheckedchangelistener (New Compoundbutton.oncheckedchangelistener () {public            void OnCheckedChanged (Compoundbutton Buttonview, Boolean isChecked) {                setuptransition (transitioner);            }        });        CheckBox DISAPPEARINGCB = (checkbox) Findviewbyid (R.ID.DISAPPEARINGCB);        Disappearingcb.setoncheckedchangelistener (New Compoundbutton.oncheckedchangelistener () {public            void OnCheckedChanged (Compoundbutton Buttonview, Boolean isChecked) {                setuptransition (transitioner);            }        });

This is two checkboxes, and we'll look at the Setuptransition method.

private void Setuptransition (layouttransition transition) {checkbox CUSTOMANIMCB = (checkbox) Findviewbyid (r.id.cu        STOMANIMCB);        CheckBox APPEARINGCB = (checkbox) Findviewbyid (R.ID.APPEARINGCB);        CheckBox DISAPPEARINGCB = (checkbox) Findviewbyid (R.ID.DISAPPEARINGCB);        CheckBox CHANGINGAPPEARINGCB = (checkbox) Findviewbyid (R.ID.CHANGINGAPPEARINGCB);        CheckBox CHANGINGDISAPPEARINGCB = (checkbox) Findviewbyid (R.ID.CHANGINGDISAPPEARINGCB);                Transition.setanimator (layouttransition.appearing, appearingcb.ischecked ()?        (customanimcb.ischecked () Customappearinganim:defaultappearinganim): null);                Transition.setanimator (layouttransition.disappearing, disappearingcb.ischecked ()?        (customanimcb.ischecked () Customdisappearinganim:defaultdisappearinganim): null);                Transition.setanimator (layouttransition.change_appearing, changingappearingcb.ischecked ()? (Customanimcb.ischecked ()? CustomchangingaPpearinganim:defaultchangingappearinganim): null);                Transition.setanimator (layouttransition.change_disappearing, changingdisappearingcb.ischecked ()? (Customanimcb.ischecked ()? Customchangingdisappearinganim:defaultchangingdisappearinganim    ): null); }

We can see that the key is Layouttransition, and the animation is based on

layouttransition.appearing;

layouttransition.disappearing;

layouttransition.change_appearing;

layouttransition.change_disappearing;

Appearing new view animation change_appearing Change the layout of the animation, then we can follow the gourd painting scoop.


 private relativelayout relativelayout;   Private Button madbtn; private int count = 0, @SuppressLint ("Newapi") protected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_animation); relativelayout = (relativelayout) findViewById ( r.id.relative) madbtn = (Button) Findviewbyid (R.ID.BTN); final GridLayout GridLayout = new GridLayout (this); Gridlayout.setcolumncount (5); Relativelayout.addview (gridLayout); Gridlayout.setlayouttransition (new               Layouttransition ()); Madbtn.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {count++;               Button button = New button (animationactivity.this); Button.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {Gridlayout.removevi               EW (v);}});               Button.settext ("btn" +count); Gridlayout.addview (button);}}); 
effect


And if we don't like the default animations, we can also replace them with the effects we like.


Madbtn.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {count++; Button button = New button (animationactivity.this); Button.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {Gridlayout.removeview (v);}}); Button.settext ("btn" + count); Layouttransition.setanimator (Layouttransition.appearing,objectanimator.offloat ( button, "RotationX", 0, Setduration); Gridlayout.setlayouttransition (layouttransition); Gridlayout.addview (button);}});

OK, attribute animation is introduced here, and I wish everyone work smoothly every day happy


Animated Animation (property Animation) for Android animation (bottom)

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.