How Android imitates the iPhone listview rotation and refresh data Animation

Source: Internet
Author: User

Http://mzh3344258.blog.51cto.com/1823534/886522

This effect is similar to the switching animation effect of the view in the iPhone. Today, we will only introduce the effects shown above. If you want to see more and more interesting activity switching effects, read the pony article: Sorry !!!

  1. Effect 1:

  2. Result 2:

  3. Effect 3:

  4. Effect 4: (the effect of pony making mistakes ):

  5. Effect 5 (maneuver effect ):

  6. Effect 6 (maneuver effect ):

Okay, after the results are finished, let's take a look at the specific code for implementing the above results, in the middle, the pony will write down all the mistakes I have tried and made in the form of comments. When you use them, do not make any mistakes!

Package COM. xiaoma. WWW; import android. animation. animator; import android. animation. animatorlisteneradapter; import android. animation. objectanimator; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. view. animation. accelerateinterpolator; import android. view. animation. cycleinterpolator; import android. view. anima Tion. decelerateinterpolator; import android. view. animation. interpolator; import android. view. animation. overshootinterpolator; import android. widget. arrayadapter; import android. widget. button; import android. widget. listview;/*** @ title: betweenanimationactivity. java * @ package COM. xiaoma. WWW * @ Description: Pony learns to imitate the iPhone list page rotation refresh * @ author xiaoma */public class betweenanimationactivity extends Act Ivity implements onclicklistener {/** resource Declaration */private button startnext = NULL; private listview firstpage = NULL; private listview secondpage = NULL; /** list item Declaration */Private Static final string firstitem [] = {"haikuo life", "glorious years", "endless emptiness", "Truly love you ", "Silent years", "gray track", "Goodbye ideal"}; Private Static final string seconditem [] = {" ", "Wahaha", "Pony fruit", "big bad guy", "cold rain night"};/** switch the animation interpolation tool on the list page to declare */private interpolator accelerator = New accelerateinterpolator (); Private interpolator decelerator = new decelerateinterpolator ();/** animation interpolation 2: effects 5 and 6 are the following interpolation devices */private interpolator accelerator1 = new cycleinterpolator (45f); Private interpolator decelerator1 = new overshootinterpolator (); /** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); SETCO Ntentview (R. layout. main);/*** write down this part. Do not write too many operations in the oncreate method as much as possible. * if many configuration problems are involved, some attribute settings must be in oncreate () * write in the method. For example, full screen and landscape screen must be written before setcontentview (). * if you write too many things in the oncreate () method, a sentence is too messy !! **/INIT ();}/*** initialization implementation */private void Init () {/** resource location, add listener */startnext = (button) findviewbyid (R. id. startnext); startnext. setonclicklistener (this); firstpage = (listview) findviewbyid (R. id. firstpage); secondpage = (listview) findviewbyid (R. id. secondpage); arrayadapter <string> firstadapter = new arrayadapter <string> (this, android. r. layout. simple_list_item_1, firstitem); arrayadapter <string> secon Dadapter = new arrayadapter <string> (this, android. r. layout. simple_list_item_1, seconditem); firstpage. setadapter (firstadapter); secondpage. setadapter (secondadapter) ;}@ override public void onclick (view v) {changepage () ;}/ ** implement list page switch */private void changepage () {final listview visiable; final listview invisiable; If (firstpage. getvisibility () = view. gone) {visiable = secondpage; invisiab Le = firstpage;} else {visiable = firstpage; invisiable = secondpage;}/** you may see the objectanimator class in this place. I didn't know what it was at first, it's easy to look up the official documents. * There are a bunch of explanations in the official documents in English. I have always said that I am dying of English, but I am not afraid. As long as you think about it, you can certainly find it out, you can only read one sentence: this class is a subclass of valueanimator. You can set an animation parameter for the target object based on the given attribute name * // effect 1 (here the effect sequence corresponds to one by one) /* Final objectanimator invistovis = objectanimator. offloat (invisiable, "rotationx",-90f, 0f); objectanimator vistoinvis = objectanimator. offlo At (visiable, "rotationx", 0f, 90f); * // effect 2 Final objectanimator invistovis = objectanimator. offloat (invisiable, "rotationy",-90f, 0f); objectanimator vistoinvis = objectanimator. offloat (visiable, "rotationy", 0f, 90f); // effect 3 (you can only note the Alpha attribute values in this region: the larger the value, the more opaque it is !!!) /* Final objectanimator invistovis = objectanimator. offloat (invisiable, "Alpha", 0.0f, 1.0f); objectanimator vistoinvis = objectanimator. offloat (visiable, "Alpha", 1.0f, 0.0f); * // ** effect 4 (this is a mistake I made, so I naively thought that the rotationz attribute name should also exist, actually, it is wrong. * This attribute name is not found in the offloat parameter, but you can still see that the list is normal. In fact, the display effect is not normal * because an error has been reported in the background, but the application will still not stop and run as usual, but the effect is only two listview replace directly. * No animation is added to it. Note that): * objectanimator. offloat (invisiable, "rotationz",-90f, 0f); */vistoinvis. setduration (1, 500); vistoinvis. setinterpolator (accelerator); invistovis. setduration (1, 500); invistovis. setinterpolator (decelerator);/** this record shows the first time this listener pony saw it. Refer to the official documentation for explanation: * this listener monitors the animation lifecycle, for example: start, end, play, and loop playback. * Remember that animation cannot be monitored. animation is only responsible for animation */vistoinvis. addlistener (New animatorlisteneradapter () {@ override public void onanimationend (animator anim) {/** lists the listening of several animations: * 1: anim. isrunning () {// todo} * 2: anim. isstarted () {// todo} * 3: anim. end () {// todo} */visiable. setvisibility (view. gone); invistovis. start (); invisiable. setvisibility (view. visible) ;}}); vistoinvis. start ();}}

Finally, in these cases, the article title says "Paging Animation". In fact, these animations are not limited to pagination. If you use the interpolation tool and animation to be more flexible, you can also make a very personalized application with a lot of animations, and the combination of animations between the activities and the above will be more perfect, you can refer to the previous article http://mzh3342138.blog.51cto.com/1823534/807337, which is helpful to you,

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.