Android parabola Download Animation production process _android

Source: Internet
Author: User

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.

Related Article

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.