项目开发偶尔会用到动画,每次都得找以前的代码复制,太麻烦了,但又记不住,只好写在这.

                ObjectAnimator.ofFloat(view, "translationX", 0, 50, -50, 0).setDuration(duration).start();//位移                ObjectAnimator.ofFloat(view, "translationY", 0, 50, -50, 0).setDuration(duration).start();                ObjectAnimator.ofFloat(view, "scaleX", 1, 2, 1).setDuration(duration).start();//缩放                ObjectAnimator.ofFloat(view, "scaleY", 1, 2, 1).setDuration(duration).start();                ObjectAnimator.ofFloat(view, "alpha", 1, 0, 1).setDuration(duration).start();//透明度                ObjectAnimator.ofFloat(view, "rotationX", 0, 180, 0).setDuration(duration).start();//翻转                ObjectAnimator.ofFloat(view, "rotationY", 0, 180, 0).setDuration(duration).start();                ObjectAnimator.ofFloat(view, "rotation", 0, 180, 0).setDuration(duration).start();//旋转             ViewHelper.setPivotX(view, view.getWidth() / 2f);//设置动画基点             ViewHelper.setPivotY(view, view.getHeight() / 2f);

以上就是比较常用的nineold,但是偶尔遇到组合的,这样就比较省事

AnimatorSet animator = new AnimatorSet();animator.playTogether(    ObjectAnimator.ofFloat(p_w_picpath, "rotation", 0, 1080),    ObjectAnimator.ofFloat(p_w_picpath, "translationX", 0, 180),    ObjectAnimator.ofFloat(p_w_picpath, "translationY", 0, -180),    ObjectAnimator.ofFloat(p_w_picpath, "scaleX", 1, 0),    ObjectAnimator.ofFloat(p_w_picpath, "scaleY", 1, 0)    ObjectAnimator.ofFloat(p_w_picpath, "alpha", 1, 0.25f, 1));animator.setDuration(5 * 1000).start();

今天做一个添加商品到购物车时 商品图片旋转 缩小 位移 到指定的购物车图标位置,用的属性动画,很麻烦,动画执行顺序如果弄乱了,位移轨迹会出问题的.大概记录一下,以免忘了

int[] endLocation = new int[2];topSpcart.getLocationInWindow(endLocation);// shopCart是那个购物车// 计算位移int endX = endLocation[0] - startLocation[0] ;// 动画位移的X坐标int endY = endLocation[1] - startLocation[1];// 动画位移的y坐标RotateAnimation rotateAnimation = new RotateAnimation(0, 1080,    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);ScaleAnimation scaleAnimation =new ScaleAnimation(1, 0, 1, 0,   Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);   TranslateAnimation translateAnimation = new TranslateAnimation(0,endX, 0, endY);//translateAnimation.setInterpolator(new LinearInterpolator());//动画加速器//translateAnimation.setInterpolator(new AccelerateInterpolator());//translateAnimation.setRepeatCount(0);// 动画重复执行的次数//translateAnimation.setFillAfter(true);//动画结束留在原位置AnimationSet set = new AnimationSet(false);set.setFillAfter(true);set.addAnimation(rotateAnimation);//旋转set.addAnimation(scaleAnimation);//缩放set.addAnimation(translateAnimation);//位移set.setDuration(1000);// 动画的执行时间view.startAnimation(set);// 动画监听事件set.setAnimationListener(new AnimationListener() {// 动画的开始@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}// 动画的结束@Overridepublic void onAnimationEnd(Animation animation) {}});


更多相关文章

  1. Android(安卓)Bitmap zoomIn/zoomOut/rotate ——图片的缩小,放大
  2. Android(安卓)中关于属性动画的一些思考,或许能为你解决一定的性
  3. android 开源组件合集-UI篇(2014-08-25更新)
  4. 个性缩放图片NinePatchDrawable
  5. Android(安卓)自定义View实现波浪动画
  6. 49.Android过渡动画的一个小练习
  7. Android动画(一)Interpolator
  8. Android滚动显示数字动画
  9. Android(安卓)多点触摸 multi-touch

随机推荐

  1. Android(安卓)Preference解读
  2. Android(安卓)获取View中的组件
  3. Android入门基础(7) ---activity生命周期
  4. map 参数学习
  5. android学习笔记23:幻灯片
  6. 【Android性能优化】内存泄露和内存溢出(O
  7. 如果我是Android面试官三
  8. Android使用ListView批量删除item的方法
  9. Android(安卓)md5加密与php md5加密一致
  10. Spring 是如何造出一个 Bean 的