android 随意漂浮动画,Android实现气泡漂浮动画,类似IOS Game Center中气泡动画
網上沒找到,于是自己寫了一個,簡單的算法,利用 PropertyValuesHolder實現多個動畫的集合,不多說,直接上代碼吧,非常好理解:
/**
*?氣泡漂浮動畫
*?@param?view
*?@param?duration??動畫運行時間
*?@param?offset????動畫運行幅度
*?@param?repeatCount???動畫運行次數
*?@return
*/
public?static?ObjectAnimator?bubbleFloat(View?view,?int?duration,?int?offset,?int?repeatCount)?{
float?path?=?(float)?(Math.sqrt(3)/2*offset);
PropertyValuesHolder?translateX?=?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)
);
PropertyValuesHolder?translateY?=?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)
);
PropertyValuesHolder?rotateX?=?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)
);
PropertyValuesHolder?rotateY?=?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)
);
ObjectAnimator?animator?=?ObjectAnimator.ofPropertyValuesHolder(view,?translateX,?translateY,?rotateX,?rotateY).
setDuration(duration);
animator.setRepeatCount(repeatCount);
animator.setInterpolator(new?LinearInterpolator());
return?animator;
}
使用方法:
bubbleFloat(view,?3000,?10,?-1);
Have a nice day!
總結
以上是生活随笔為你收集整理的android 随意漂浮动画,Android实现气泡漂浮动画,类似IOS Game Center中气泡动画的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2011年9月计算机C语言真题,2011
- 下一篇: android 属性动画失败,Andro