"Android Development Art Exploration" reading notes (Fri)--drawable
NO1:
Custom Animation : Derive a new animation only need to inherit animation this abstract class, and then rewrite its initialize and Applytransformation methods, in the Initialize method to do some initialization work, It is necessary to make the corresponding matrix transformation in the applytransformation, and it is often required to use camera to simplify the matrix transformation process.
No2:
Property animation Propertyanimation Motion tween tweenanimation frame animation frameanimationNo3: , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp layoutanimation: Layoutanimation acts onViewGroup, assign an animation to ViewGroup so that it will animate when its child elements appear. This effect is often used on the ListView.
//res/anim/anim_layout.xml < xmlns:android= "http://schemas.android.com/apk/res/android" android: Animation= "@anim/anim_item" android:animationorder= "normal" Android:delay = "0.5" />
//res/anim/anim_item.xml<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"android:duration= "$"Android:interpolator= "@android: Anim/accelerate_interpolator"Android:shareinterpolator= "true"> <AlphaAndroid:fromalpha= "0.0"Android:toalpha= "1.0" /> <TranslateAndroid:fromxdelta= "+"Android:toxdelta= "0" /></Set>
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/activity_main"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.administrator.layoutanimation.MainActivity"> <ListViewAndroid:id= "@+id/list"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#fff4f7f9"Android:cachecolorhint= "#00000000"Android:divider= "#dddbdb"Android:dividerheight= "1.0px"android:layoutanimation= "@anim/anim_layout"Android:listselector= "@android: Color/transparent" /></Relativelayout>
It can also be achieved by Layoutanimationcontroller.
ListView ListView == animationutils.loadanimation (Thisnew Layoutanimationcontroller (animation); Controller.setdelay (0.5f); Controller.setorder ( Layoutanimationcontroller.order_normal); listview.setlayoutanimation (Controller);
No4:
activity Switch effect, mainly used in overridependingtransition(int enteranim,int Exitanim), this method must be in StartActivity ( Intent) or Finish () after the call to take effect
Enteranim--activity is turned on, the desired animation resource ID
Exitanim--activity is paused, the desired animation resource ID
fragment Toggle animation, can be achieved through the Setcustomanimations () method in Fragmenttransaction. Toggle animation needs to be a view animation
NO5:
Property animations can animate the properties of any object , not just the view, using the Open Source animation library Nineoldandroids to be compatible with previous versions
NO6:
timeinterpolator time Interpolator, which calculates the percentage of the current attribute value change based on the percentage of elapsed time.
The typeevaluator type Valuation Algorithm (estimator) that calculates the changed attribute value based on the percentage of the current attribute change.
Custom interpolation requires implementation of Interpolator or Timeinterpolator, and custom valuation algorithms need to implement Typeevaluator.
No7:Animatorlisteneryou can listen to the start, end, Cancel, and repeat playback of an animation. Animatorupdatelistenercan listen to the entire process, the animation every frame play, onanimationupdate will be called once. No8:We animate the property of object ABC, and if you want the animation to take effect, you need to satisfy bothTwo conditions1) object must be providedSETABCmethod, if the animation does not pass the initial value, then also provideGETABCmethod, because the system is going to fetch the initial value of the ABC property (if this is not satisfied, the program directly crash) 2) object setabc changes to attribute ABC must be reflected in some way, such as bringingchanges to the UI(If this is not satisfied, the animation is ineffective but not crash) solves the method that does not satisfy the condition two:
Private voidperformanimate () {Viewwrapper wrapper=NewViewwrapper (Mbutton); Objectanimator.ofint (Wrapper,"width"). Setduration (5000). Start ();} @Override Public voidOnClick (View v) {if(v = =Mbutton) {performanimate (); }}Private Static classviewwrapper{PrivateView Mtarget; PublicViewwrapper (View target) {mtarget=Target; } Public voidSetWidth (intwidth) {Mtarget.getlayoutparams (). Width=width; Mtarget.requestlayout (); }}
No9:
The Valueanimator listens to the animation process, which itself does not work for any object. It can animate a value , and then we can listen to its animation process and modify the property values of our objects during the animation, which is equivalent to animating our objects.
No10:
Use animation considerations:
1)Oom--the number of frames animated pictures is large and the picture is very easy to appear oom
2) memory leak -- Infinite loop Property animation needs to stop when activity exits, otherwise the activity cannot be released causing memory leak, view animation does not exist this problem
3) compatible --animations under 3.0 have compatibility issues with the system
4) need to use px--try to use DP
5) Animation element Interaction--Property animation and Click event Trigger location for view animation
6) Hardware acceleration --hardware acceleration improves the fluency of animations
"Android Development Art Exploration" reading notes (v)--animation