网上没找到,于是自己写了一个,简单的算法,利用 PropertyValuesHolder实现多个动画的集合,不多说,直接上代码吧,非常好理解:
/**
*气泡漂浮动画
*@paramview
*@paramduration动画运行时间
*@paramoffset动画运行幅度
*@paramrepeatCount动画运行次数
*@return
*/
publicstaticObjectAnimatorbubbleFloat(Viewview,intduration,intoffset,intrepeatCount){
floatpath=(float)(Math.sqrt(3)/2*offset);
PropertyValuesHoldertranslateX=PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X,
Keyframe.ofFloat(0f,0),
Keyframe.ofFloat(1/12f,offset/2),
Keyframe.ofFloat(2/12f,path),
Keyframe.ofFloat(3/12f,offset),
Keyframe.ofFloat(4/12f,path),
Keyframe.ofFloat(5/12f,offset/2),
Keyframe.ofFloat(6/12f,0),
Keyframe.ofFloat(7/12f,-offset/2),
Keyframe.ofFloat(8/12f,-path),
Keyframe.ofFloat(9/12f,-offset),
Keyframe.ofFloat(10/12f,-path),
Keyframe.ofFloat(11/12f,-offset/2),
Keyframe.ofFloat(1f,0)
);
PropertyValuesHoldertranslateY=PropertyValuesHolder.ofKeyframe(View.TRANSLATION_Y,
Keyframe.ofFloat(0f,0),
Keyframe.ofFloat(1/12f,offset-path),
Keyframe.ofFloat(2/12f,offset/2),
Keyframe.ofFloat(3/12f,offset),
Keyframe.ofFloat(4/12f,offset*3/2),
Keyframe.ofFloat(5/12f,offset+path),
Keyframe.ofFloat(6/12f,offset*2),
Keyframe.ofFloat(7/12f,offset+path),
Keyframe.ofFloat(8/12f,offset*3/2),
Keyframe.ofFloat(9/12f,offset),
Keyframe.ofFloat(10/12f,offset/2),
Keyframe.ofFloat(11/12f,offset-path),
Keyframe.ofFloat(1f,0)
);
PropertyValuesHolderrotateX=PropertyValuesHolder.ofKeyframe(View.ROTATION_X,
Keyframe.ofFloat(0f,0),
Keyframe.ofFloat(1/12f,offset/2),
Keyframe.ofFloat(2/12f,path),
Keyframe.ofFloat(3/12f,offset),
Keyframe.ofFloat(4/12f,path),
Keyframe.ofFloat(5/12f,offset/2),
Keyframe.ofFloat(6/12f,0),
Keyframe.ofFloat(7/12f,-offset/2),
Keyframe.ofFloat(8/12f,-path),
Keyframe.ofFloat(9/12f,-offset),
Keyframe.ofFloat(10/12f,-path),
Keyframe.ofFloat(11/12f,-offset/2),
Keyframe.ofFloat(1f,0)
);
PropertyValuesHolderrotateY=PropertyValuesHolder.ofKeyframe(View.ROTATION_Y,
Keyframe.ofFloat(0f,0),
Keyframe.ofFloat(1/12f,offset/2),
Keyframe.ofFloat(2/12f,path),
Keyframe.ofFloat(3/12f,offset),
Keyframe.ofFloat(4/12f,path),
Keyframe.ofFloat(5/12f,offset/2),
Keyframe.ofFloat(6/12f,0),
Keyframe.ofFloat(7/12f,-offset/2),
Keyframe.ofFloat(8/12f,-path),
Keyframe.ofFloat(9/12f,-offset),
Keyframe.ofFloat(10/12f,-path),
Keyframe.ofFloat(11/12f,-offset/2),
Keyframe.ofFloat(1f,0)
);
ObjectAnimatoranimator=ObjectAnimator.ofPropertyValuesHolder(view,translateX,translateY,rotateX,rotateY).
setDuration(duration);
animator.setRepeatCount(repeatCount);
animator.setInterpolator(newLinearInterpolator());
returnanimator;
}
使用方法:
bubbleFloat(view,3000,10,-1);
Have a nice day!
如果觉得《android 随意漂浮动画 Android实现气泡漂浮动画 类似IOS Game Center中气泡动画》对你有帮助,请点赞、收藏,并留下你的观点哦!