Nineoldandroid detailed use and implementation of Drawerlayout slide animation

Source: Internet
Author: User

Nineoldandroid.view.ViewHelpe is an animated open source library for compatibility with 3.0 or less

Correlation function Interpretation: (the first parameter is an animated object, the second is an animated property value change expression)

Viewhelper.settranslationx (,);//x direction shift

Viewhelper.settranslationy (,);

Viewhelper.setscalex (,); x direction change size

Viewhelper.setscaley (,);

Viewhelper.setalpha (,); Transparency changes

Viewhelper.setpivoty (,); The center of the X-direction of size change

Viewhelper.setpivotx (,);

For example, in drawerlayout by listening to the drawerlayout of the slide to set the animation (here the listener starts to set ... is obsolete, there is no difference between the two, but will be judged whether it is empty at a time)

Mdrawerlayout.adddrawerlistener (NewDrawerlistener ()//set up a pull listener event to add a listener        {             Public voidOndrawerstatechanged (intNewState)//Status Monitoring            {            }             Public voidOndrawerslide (View Drawerview,floatSlideoffset)//Slide Monitoring{View mcontent= Mdrawerlayout.getchildat (0);//returns a child view with an index of 0 in the drawer layoutView Mmenu =Drawerview; floatScale =1-Slideoffset;//offset causes scale from 1.0-0.0                floatRightScale =0.8f+ Scale *0.2f;//Convert content area from 1.0-0.0 to 1.0-0.8                if(Drawerview.gettag (). Equals (" Left"))                {                    floatLeftscale =1-0.3f* SCALE;//0.7-1.0Viewhelper.setscalex (Mmenu, Leftscale);                    Viewhelper.setscaley (Mmenu, Leftscale); Viewhelper.setalpha (Mmenu,0.6f+0.4f* (1-scale));//starting here is set to this, causing background transparency to have 1.0-0.6//Viewhelper.setalpha (Mmenu, 0.6f + 0.4f * scale);Viewhelper.settranslationx (Mcontent, Mmenu.getmeasuredwidth ()* (1-scale )); Viewhelper.setpivotx (Mcontent,0); Viewhelper.setpivoty (Mcontent, Mcontent.getmeasuredheight ()/2);                    Mcontent.invalidate ();                    Viewhelper.setscalex (Mcontent, RightScale);                Viewhelper.setscaley (Mcontent, RightScale); } Else{Viewhelper.settranslationx (mcontent,-mmenu.getmeasuredwidth () *slideoffset); //Set the center of the size changeViewhelper.setpivotx (Mcontent, Mcontent.getmeasuredwidth ()); Viewhelper.setpivoty (Mcontent, Mcontent.getmeasuredheight ()/2);                    Mcontent.invalidate ();                    Viewhelper.setscalex (Mcontent, RightScale);                Viewhelper.setscaley (Mcontent, RightScale); }            }             Public voidondraweropened (View drawerview) {} Public voidondrawerclosed (View drawerview) {Mdrawerlayout.setdrawerlockmode (D            rawerlayout.lock_mode_locked_closed, Gravity.right); }        });


About the conversion of animation properties in sliding:

1, the first is the content area of the scaling scale calculation:

We're going to let the content area change from 1.0~0.8 as the menu appears.

Float RightScale = 0.8f + scale * 0.2F; (scale from 1 to 0)

2. Scale calculation of menu

Carefully observe the next QQ, the menu probably zoom change is 0.7~1.0

float Leftscale = 1-0.3f * scale;

3, the transparency ratio of the menu:

We set it to 0.6~1.0:0.6f + 0.4f * (1-scale)

4. The X-Direction offset of the menu:

Look at QQ, not completely from being covered by the content area, or there is a little drag out of the feeling, so our offset so set:

Tranlatex = mmenuwidth * scale * 0.6f;

Nineoldandroid detailed use and implementation of Drawerlayout slide animation

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.