Android Development: The sharing effect of driving pictures

Source: Internet
Author: User

These days to do a drive to share the picture page, now share it out, if you feel useful, please use directly, avoid repeating the wheel

Let's see.

Think it's just not obvious, then use your phone to scan the QR code below to download the installation package:

This effect itself is not any particular difficulty, are implemented with animator, but the animation effect of a bit more code, because the share module will do, share it, want to use, do not repeat so many lines of code

For people who are familiar with animator, the following code can be skipped

I'm looking at the main implementation code, the full code look at the bottom of the project GitHub address

1. I used a method to achieve the effect of entry, plus the decision, whether the need to hide the QR code page

private void Moveinanim (Boolean ishidecode) {objectanimator Friendanimatorx = Objectanimator. Offloat(Tvfriend,"Translationx",0);Objectanimator friendanimatory = Objectanimator. Offloat(Tvfriend,"Translationy",0);Objectanimator Timelineanimatorx = Objectanimator. Offloat(Tvtimeline,"Translationx",0);Objectanimator timelineanimatory = Objectanimator. Offloat(Tvtimeline,"Translationy",0);Objectanimator Qrcodeanimatorx = Objectanimator. Offloat(Tvqrcode,"Translationx",0);Objectanimator qrcodeanimatory = Objectanimator. Offloat(Tvqrcode,"Translationy",0);Objectanimator Copyanimatorx = Objectanimator. Offloat(Tvcopylink,"Translationx",0);Objectanimator copyanimatory = Objectanimator. Offloat(Tvcopylink,"Translationy",0);AnimatorsetSet= new Animatorset ();        Set. Setduration(Anim_time);if (ishidecode) {Objectanimator Animatorx = Objectanimator. Offloat(Tvcode,"ScaleX",0.1F;Objectanimator animatory = Objectanimator. Offloat(Tvcode,"ScaleY",0.1F;            Set. AddListener(New Animatorlisteneradapter () {@Override public void Onanimationend (Animator animation) { Tvcode. Setvisibility(View. INVISIBLE);}            });            Set. Playtogether(Friendanimatorx, Friendanimatory, Timelineanimatorx, Timelineanimatory, Qrcodeanimatorx, QrcodeAnimat OrY, Copyanimatorx, Copyanimatory, Animatorx, Animatory);} else {Set. Setinterpolator(New Fastoutslowininterpolator ());            Set. Playtogether(Friendanimatorx, Friendanimatory, Timelineanimatorx, Timelineanimatory, Qrcodeanimatorx, QrcodeAnimat OrY, Copyanimatorx, Copyanimatory);}Set. Start();}

In the animator to achieve the x-axis and the y-axis, as well as the effect of scaling, the conscientious may find that why I moved the parameters are 0f, then the starting value where to go, please continue to see the 2nd.

2. Initialize Location

Tvfriend.getviewtreeobserver (). Addonpredrawlistener (NewViewtreeobserver.onpredrawlistener () {@Override             Public Boolean Onpredraw() {tvfriend.getviewtreeobserver (). Removeonpredrawlistener ( This); Tvfriend.settranslationx (-screenwidth/2); Tvfriend.settranslationy (-tvfriend.getheight () *2);return false;        }        }); Tvtimeline.getviewtreeobserver (). Addonpredrawlistener (NewViewtreeobserver.onpredrawlistener () {@Override             Public Boolean Onpredraw() {tvtimeline.getviewtreeobserver (). Removeonpredrawlistener ( This); Tvtimeline.settranslationx (ScreenWidth/2); Tvtimeline.settranslationy (-tvfriend.getheight () *2);return false;        }        }); Tvqrcode.getviewtreeobserver (). Addonpredrawlistener (NewViewtreeobserver.onpredrawlistener () {@Override             Public Boolean Onpredraw() {tvqrcode.getviewtreeobserver (). Removeonpredrawlistener ( This); Tvqrcode.settranslationx (-screenwidth/2); Tvqrcode.settranslationy (Tvfriend.getheight () *2);return false;        }        }); Tvcopylink.getviewtreeobserver (). Addonpredrawlistener (NewViewtreeobserver.onpredrawlistener () {@Override             Public Boolean Onpredraw() {tvcopylink.getviewtreeobserver (). Removeonpredrawlistener ( This); Tvcopylink.settranslationx (ScreenWidth/2); Tvcopylink.settranslationy (Tvfriend.getheight () *2);return false; }        });

The way to initialize the position is to be placed in the Addonpredrawlistener, which is why in the previous point, as long as the value is set to 0f is the reason

3. Moving out of the animation

private void Moveoutanim (Boolean isfinishactivity, Boolean isshowcode) {objectanimator Friendanimatorx = Objectani Mator. Offloat(Tvfriend,"Translationx",-screenwidth/2);Objectanimator friendanimatory = Objectanimator. Offloat(Tvfriend,"Translationy",-tvfriend. GetHeight() *2);Objectanimator Timelineanimatorx = Objectanimator. Offloat(Tvtimeline,"Translationx", ScreenWidth/2);Objectanimator timelineanimatory = Objectanimator. Offloat(Tvtimeline,"Translationy",-tvfriend. GetHeight() *2);Objectanimator Qrcodeanimatorx = Objectanimator. Offloat(Tvqrcode,"Translationx",-screenwidth/2);Objectanimator qrcodeanimatory = Objectanimator. Offloat(Tvqrcode,"Translationy", Tvfriend. GetHeight() *2);Objectanimator Copyanimatorx = Objectanimator. Offloat(Tvcopylink,"Translationx", ScreenWidth/2);Objectanimator copyanimatory = Objectanimator. Offloat(Tvcopylink,"Translationy", Tvfriend. GetHeight() *2);AnimatorsetSet= new Animatorset ();        Set. Setduration(Anim_time);if (Isshowcode) {Addqrcode ();Objectanimator Animatorscalex = Objectanimator. Offloat(Tvcode,"ScaleX",1F;Objectanimator Animatorscaley = Objectanimator. Offloat(Tvcode,"ScaleY",1F;Animatorscalex. Setinterpolator(Overshootinterpolator);Animatorscaley. Setinterpolator(Overshootinterpolator);            Set. Playtogether(Friendanimatorx, Friendanimatory, Timelineanimatorx, Timelineanimatory, Qrcodeanimatorx, QrcodeAnimat OrY, Copyanimatorx, Copyanimatory, Animatorscalex, Animatorscaley);} else {Set. Playtogether(Friendanimatorx, Friendanimatory, Timelineanimatorx, Timelineanimatory, Qrcodeanimatorx, QrcodeAnimat OrY, Copyanimatorx, Copyanimatory);} if (isfinishactivity) {Set. AddListener(New Animatorlisteneradapter () {@Override public void Onanimationend (Animator animation) { Finish ();Overridependingtransition (0,0);}            });}Set. Start();}

It's the same as moving the animation.

4. When you start the page, start the animation method:

tvFriend.post(new Runnable() {            @Override            publicvoidrun() {                moveInAnim(false);            }        });

Using the Post method, can be very good to achieve the beginning of the animation, if directly in the Onresume call, or other places call, will appear stuttering, as to why this method can, or there is no better way, hope to have familiar with the handle and other people to explain, thanks

5. Place of attention
Some phones will have the default page switch animation, such as my M2 phone is to swipe to the left, exit is to the right, in order to avoid some of the phone's default animation, you can start the page and exit the page after the code, add the following code, to avoid the default transition effect

overridePendingTransition(0, 0);

The source code of the project I put on GitHub, welcome to view!

Have any questions or discuss, please leave a message or contact me

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Development: The sharing effect of driving pictures

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.