失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android 随意漂浮动画 Android实现气泡漂浮动画 类似IOS Game Center中气泡动画

android 随意漂浮动画 Android实现气泡漂浮动画 类似IOS Game Center中气泡动画

时间:2021-11-23 06:14:13

相关推荐

android 随意漂浮动画 Android实现气泡漂浮动画 类似IOS Game Center中气泡动画

网上没找到,于是自己写了一个,简单的算法,利用 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中气泡动画》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。