Recently there was a small need to add an uploaded animation to the data upload, and then to try to write a frame animation
Upload the beginning of the call animation, upload the end of the notification container to delete it (this method should not be too much memory), and then spit out the GIF picture or I frame a frames from PS and then save as a PNG format, hey, reward yourself to be so omnipotent
Write frame animation before you need to write a frame list, named Upload_anim.xml
<?XML version= "1.0" encoding= "Utf-8"?><animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"Android:oneshot= "false"> <Itemandroid:drawable= "@drawable/s1"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s2"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s3"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s4"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s5"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s6"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s7"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s8"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s9"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s10"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s11"android:duration= " the" /> <Itemandroid:drawable= "@drawable/s12"android:duration= " the" /></animation-list>
For example, this is a 12-frame animation resource file, let's see how he uses, here to talk about the ImageView is able to play as shown in the code above the list of frames
I only need to use the above frame list as Drawbale in the ImageView resources, and then we get this resource to play it! Can be achieved, and then add ImageView's entry animation! Perfect
ImageView ImageView =NewImageView (context); Animationin=animationutils.loadanimation (context,r.anim.in); Imageview.setanimation (Animationin); Imageview.setimageresource (R.drawable.upload_anim); Final animationdrawable animationdrawable = (animationdrawable) imageview.getdrawable (); Animationdrawable.start (); Viewgroup.layoutparams.wrap_content,viewgroup.layoutparams.wrap_content); Linearlayout.layoutparams params=NewLinearlayout.layoutparams (50,50); Rlcontentmain.addview (Imageview,params);
Note: There are undeclared variables above Animationin are animation types Rlcontentmain is a layout of the Relativelayout type in order to place the animation (I put this animation in the relativelayout and then animate it, then I have the effect of clicking and animating (*^__^*), The params is set to control the size of the animation resource)
Key code Analysis: The key code to play the animation resources is the red code, first define a animationdrawable and then its instance from the ImageView get to, and then directly start () can play up
And then I have r.anim.in. This is an animation of a ImageView entry, the code is as follows
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate android:fromydelta= " -100%p" android:duration= "/>" </set>
The implementation is a simple displacement animation, Fromydelta is the source code interpretation: Change in Y coordinate to apply at the start of the animation is to be applied to the animation c5> the change in the Y- coordinate of the opening;
It's done.
And of course there are other animations like gradients, acceleration, etc.
Android implements frame animations, as well as animations on the exit