Android-animation Advanced (Create user-friendly animations)

Source: Internet
Author: User

Android commonly used animation has animation, animator two kinds;

---The 1th common use is in activity switching. For example, open an activity. Close an activity a person prefers the effect of sliding left and right (as for how XML is configured tween animation is not in the repeat, the Internet is everywhere)

1. Activate activity

        private void Gotoregistactivity () {Intent intent=new Intent (); Intent.setclass (Getactivity (), registactivity.class); StartActivity (intent); Getactivity (). Overridependingtransition (r.anim.slide_right_in,r.anim.slide_left_out);}

2. Close activity (here a personal project does an activity base class that implements code in the base class)

        @Overridepublic boolean onKeyDown (int keyccode, keyevent keyevent) {if (keyccode==keyevent.keycode_back) {this.finish ( ); Overridependingtransition (r.anim.slide_left_in,r.anim.slide_right_out); return true;} Return Super.onkeydown (Keyccode, keyevent);}

---animator configuration

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <objectanimator        android:interpolator= "@android: Interpolator/decelerate_quint"        android: Valuefrom= "200DP" android:valueto= "0DP"        android:valuetype= "Floattype"        android:propertyname= " Translationx "        android:duration=" "/>    <objectanimator        android:interpolator=" @android: Interpolator/decelerate_quint "        android:valuefrom=" 0.0 "android:valueto=" 1.0 "        android:valuetype=" Floattype "        android:propertyname=" Alpha "        android:duration="/></set>

2. General animator is configured on the new API, such as we are familiar with the fragment inside, the Internet to find a bit, said is Add,remove, before the call, tested, after the fragmenttransaction opened the transaction

Call: (The following code has an effect before calling detach (), slide's XML is based on a slight change above, and if the reader wants to see things time, suggest adding animation time observations):

Mtransaction.setcustomanimations (r.anim.slide_frag_in,r.anim.slide_frag_out);





Android-animation Advanced (Create user-friendly animations)

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.