下载动画经常出现在下载需求多的app中,比如游戏下载平台,应用市场……
先看看效果图:
实现
private voID startAnim() { //以bitmap创建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);}
设置动画
private voID setAnim(final ImageVIEw logo,int[] startLocation,int[] location_download) { VIEwGroup animMaskLayout = createAnimLayout(); animMaskLayout.addVIEw(logo);// 把动画小球添加到动画层 // 计算位移 final VIEw vIEw = addVIEwToAnimLayout(logo,startLocation); // 动画位移的X坐标 int endY = location_download[1] - startLocation[1]; // 动画位移的y坐标 TranslateAnimation translateAnimationX = new TranslateAnimation(0,endX,0); translateAnimationX.setInterpolator(new linearInterpolator()); translateAnimationX.setRepeatCount(0);// 动画重复执行的次数 translateAnimationX.setFillAfter(true); TranslateAnimation translateAnimationY = new TranslateAnimation(0,endY); translateAnimationY.setInterpolator(new AccelerateInterpolator()); translateAnimationY.setRepeatCount(0);// 动画重复执行的次数 translateAnimationX.setFillAfter(true); AnimationSet set = new AnimationSet(false); set.setFillAfter(false); set.addAnimation(translateAnimationY); set.addAnimation(translateAnimationX); set.setDuration(2000);// 动画的执行时间 vIEw.startAnimation(set); // 动画监听事件 set.setAnimationListener(new Animation.AnimationListener() { // 动画的开始 @OverrIDe public voID onAnimationStart(Animation animation) { logo.setVisibility(VIEw.VISIBLE); } @OverrIDe public voID onAnimationRepeat(Animation animation) { } // 动画的结束 @OverrIDe public voID onAnimationEnd(Animation animation) { logo.setVisibility(VIEw.GONE); } });}
创建动画父布局
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;}
设置动画布局参数
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;}
代码就到此结束了,看起来并不难,动手试试吧。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的Android抛物线下载动画制作过程全部内容,希望文章能够帮你解决Android抛物线下载动画制作过程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)