Android 属性动画备忘 nineold
项目开发偶尔会用到动画,每次都得找以前的代码复制,太麻烦了,但又记不住,只好写在这.
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,但是偶尔遇到组合的,这样就比较省事
AnimatorSetanimator=newAnimatorSet();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=newint[2];topSpcart.getLocationInWindow(endLocation);//shopCart是那个购物车//计算位移intendX=endLocation[0]-startLocation[0];//动画位移的X坐标intendY=endLocation[1]-startLocation[1];//动画位移的y坐标RotateAnimationrotateAnimation=newRotateAnimation(0,1080,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);ScaleAnimationscaleAnimation=newScaleAnimation(1,0,1,0,Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0);TranslateAnimationtranslateAnimation=newTranslateAnimation(0,endX,0,endY);//translateAnimation.setInterpolator(newLinearInterpolator());//动画加速器//translateAnimation.setInterpolator(newAccelerateInterpolator());//translateAnimation.setRepeatCount(0);//动画重复执行的次数//translateAnimation.setFillAfter(true);//动画结束留在原位置AnimationSetset=newAnimationSet(false);set.setFillAfter(true);set.addAnimation(rotateAnimation);//旋转set.addAnimation(scaleAnimation);//缩放set.addAnimation(translateAnimation);//位移set.setDuration(1000);//动画的执行时间view.startAnimation(set);//动画监听事件set.setAnimationListener(newAnimationListener(){//动画的开始@OverridepublicvoidonAnimationStart(Animationanimation){}@OverridepublicvoidonAnimationRepeat(Animationanimation){}//动画的结束@OverridepublicvoidonAnimationEnd(Animationanimation){}});
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。