Download the animation often appears in the download demand many apps, such as Game download platform, application market ...
First look at the effect chart:
Realize
private void Startanim () {
//is bitmap to create new ImageView
iv.setdrawingcacheenabled (true);
Bitmap Bitmap = Iv.getdrawingcache ();
ImageView logo = new ImageView (this);
Logo.setscaletype (ImageView.ScaleType.FIT_XY);
Logo.setimagebitmap (bitmap);
int[] startlocation = new int[2];
Iv.getlocationinwindow (startlocation);
End.getlocationinwindow (location_download);
Setanim (Logo, startlocation, location_download);
}
Set animation
private void Setanim (final ImageView logo, int[] startlocation,int[] location_download) {ViewGroup animmasklayout = C
Reateanimlayout ();
Animmasklayout.addview (Logo)//To add animation ball to the animation layer/calculation Displacement final View view = addviewtoanimlayout (logo, startlocation);
Animation displacement of the x coordinate int endY = location_download[1]-startlocation[1];
The y-coordinate of the animation displacement translateanimation Translateanimationx = new Translateanimation (0, endx, 0, 0);
Translateanimationx.setinterpolator (New Linearinterpolator ()); Translateanimationx.setrepeatcount (0);//The number of times the animation repeats Translateanimationx.setfillafter (true);
Translateanimation translateanimationy = new Translateanimation (0, 0, 0, EndY);
Translateanimationy.setinterpolator (New Accelerateinterpolator ()); Translateanimationy.setrepeatcount (0);//The number of times the animation repeats Translateanimationx.setfillafter (true);
Animationset set = new Animationset (false);
Set.setfillafter (FALSE);
Set.addanimation (Translateanimationy);
Set.addanimation (Translateanimationx);Set.setduration (2000);//Animation Execution Time view.startanimation (set); Animation Listener Event Set.setanimationlistener (new Animation.animationlistener () {//animation start @Override public vo
ID Onanimationstart (Animation Animation) {logo.setvisibility (view.visible); @Override public void Onanimationrepeat (Animation Animation) {}//end of animation @Override P
ublic void Onanimationend (Animation Animation) {logo.setvisibility (view.gone);
}
});
}
Create an animated parent layout
Private ViewGroup Createanimlayout () {
ViewGroup Rootview = (viewgroup) GetWindow (). Getdecorview ();
LinearLayout animlayout = new LinearLayout (this);
Linearlayout.layoutparams LP = new Linearlayout.layoutparams (
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
ANIMLAYOUT.SETLAYOUTPARAMS (LP);
Animlayout.setid (integer.max_value);
Animlayout.setbackgroundresource (Android. r.color.transparent);
Rootview.addview (animlayout);
return animlayout;
}
Set Animation layout parameters
private static View Addviewtoanimlayout (final view view, int[] location) {
int x = location[0];
int y = location[1];
Linearlayout.layoutparams LP = new Linearlayout.layoutparams (n);
Lp.leftmargin = x;
Lp.topmargin = y;
VIEW.SETLAYOUTPARAMS (LP);
return view;
}
That's the end of the code, it doesn't look too hard, just try it.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.