Android Open Source Code learning--noboringactionbar

Source: Internet
Author: User

Code features

The example project implements a custom actionbar that allows a smooth transition of a picture to the position of the Actionbar icon, and is presented in the form of Actionbar icon. It also realizes the automatic switch of the background image, zooming and moving. Can be used in scenarios such as displaying user profiles .

Key Code Learning

2.1 Noboringactionbaractivity.java

Settitlealpha (Clamp (5.0F * ratio-4.0f, 0.0F, 1.0F));

Note: This line of code is used to set the transparency of the Actionbar title, which controls that the title does not begin to display until it moves up to 4/5 of the total movable height.

 Public Static Float Clamp (floatfloat float max) {    return  Math.max ( Min, math.min (value, max));}

Note: This method limits value to the range of [Min,max]

2.2 Kenburnsview.java

Handler.post (Runnable R);

Note: Add the instance object of the parameter runnable to the handler message queue

Handler.removecallbacks (Runnable R);

Note: Remove the instance object of the parameter runnable from the message queue

Private voidStart (View view,LongDurationfloatFromscale,floatToscale,floatFromtranslationx,floatFromtranslationy,floatTotranslationx,floattotranslationy)        {View.setscalex (Fromscale);        View.setscaley (Fromscale);        View.settranslationx (Fromtranslationx);        View.settranslationy (Fromtranslationy); Viewpropertyanimator Propertyanimator=view.animate (). Translationx (Totranslationx). Translationy (Totranslationy). ScaleX (Toscale). ScaleY (ToSca        Le). setduration (duration);        Propertyanimator.start (); LOG.D (TAG,"Starting Ken Burns animation" +propertyanimator);}

Note: The effect of performing this method is to make the background picture shift randomly, zooming.

System API Usage and understanding

3.1 Viewpropertyanimator


This class may provide better performance for several simultaneous animations, because it'll optimize invalidate calls T o take place-once for several properties instead of each animated property independently causing its own invalidation .
According to the official API, this class performs better when several animations are executed simultaneously.

Summarize


Such a simple demo himself Leng took 3 weeks to sort out, too drag. And the animation of the piece of the thing is still no thoroughly understand, perhaps a few days will be sent a blog about the Android animation. Not verbose, attachment for their own simple annotated code, interested students can study.

HTTP://YUNPAN.CN/CFGZLJBZS6UDK Access Password B0c7

Android Open Source Code learning--noboringactionbar

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.