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