欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android拋物線下載動(dòng)畫制作過(guò)程

 更新時(shí)間:2016年11月29日 14:08:58   作者:Harryhtt  
這篇文章主要為大家詳細(xì)介紹了Android拋物線下載動(dòng)畫制作過(guò)程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

下載動(dòng)畫經(jīng)常出現(xiàn)在下載需求多的app中,比如游戲下載平臺(tái),應(yīng)用市場(chǎng)……

先看看效果圖:

實(shí)現(xiàn)

private void startAnim() {  
  //以bitmap創(chuàng)建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);
}

設(shè)置動(dòng)畫

private void setAnim(final ImageView logo, int[] startLocation,int[] location_download) {  
 ViewGroup animMaskLayout = createAnimLayout();  
 animMaskLayout.addView(logo);// 把動(dòng)畫小球添加到動(dòng)畫層 
 // 計(jì)算位移
 final View view = addViewToAnimLayout(logo, startLocation);
 // 動(dòng)畫位移的X坐標(biāo)   
 int endY = location_download[1] - startLocation[1];
 // 動(dòng)畫位移的y坐標(biāo)  
 TranslateAnimation translateAnimationX = new TranslateAnimation(0,  endX, 0, 0);  
 translateAnimationX.setInterpolator(new LinearInterpolator());   
 translateAnimationX.setRepeatCount(0);// 動(dòng)畫重復(fù)執(zhí)行的次數(shù)  
 translateAnimationX.setFillAfter(true);  TranslateAnimation 
 translateAnimationY = new TranslateAnimation(0, 0, 0, endY);   
 translateAnimationY.setInterpolator(new AccelerateInterpolator());  
 translateAnimationY.setRepeatCount(0);// 動(dòng)畫重復(fù)執(zhí)行的次數(shù)  
 translateAnimationX.setFillAfter(true);  AnimationSet set = new 
 AnimationSet(false); 
 set.setFillAfter(false);  
 set.addAnimation(translateAnimationY);  
 set.addAnimation(translateAnimationX); 
 set.setDuration(2000);// 動(dòng)畫的執(zhí)行時(shí)間  
 view.startAnimation(set);  // 動(dòng)畫監(jiān)聽事件  
 set.setAnimationListener(new Animation.AnimationListener() {  
    // 動(dòng)畫的開始    
    @Override  
    public void onAnimationStart(Animation animation) {  
       logo.setVisibility(View.VISIBLE);  
   }     
   @Override 
   public void onAnimationRepeat(Animation animation) {  
   }   
   // 動(dòng)畫的結(jié)束    
   @Override  
   public void onAnimationEnd(Animation animation) {      
       logo.setVisibility(View.GONE);  
   } 
  });
}

創(chuàng)建動(dòng)畫父布局

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;
}

設(shè)置動(dòng)畫布局參數(shù)

private static View addViewToAnimLayout(final View view, int[] location) { 
 int x = location[0]; 
 int y = location[1]; 
 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(80, 80); 
 lp.leftMargin = x; 
 lp.topMargin = y; 
 view.setLayoutParams(lp); 
 return view;
}

代碼就到此結(jié)束了,看起來(lái)并不難,動(dòng)手試試吧。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論