- 轉(zhuǎn)載請(qǐng)注明出處裆站,謝謝
Android Property Animation
動(dòng)畫有很多大神寫過,都非常好宏胯,這里只通過ObjectAnimator /ValueAnimator實(shí)現(xiàn)上下左右浮動(dòng)效果。
很簡(jiǎn)單看代碼就好
private void floatAnim(View view,int delay){
List<Animator> animators = new ArrayList<>();
ObjectAnimator translationXAnim = ObjectAnimator.ofFloat(view, "translationX", -6.0f,6.0f,-6.0f);
translationXAnim.setDuration(1500);
translationXAnim.setRepeatCount(ValueAnimator.INFINITE);//無限循環(huán)
translationXAnim.setRepeatMode(ValueAnimator.INFINITE);//
translationXAnim.start();
animators.add(translationXAnim);
ObjectAnimator translationYAnim = ObjectAnimator.ofFloat(view, "translationY", -3.0f,3.0f,-3.0f);
translationYAnim.setDuration(1000);
translationYAnim.setRepeatCount(ValueAnimator.INFINITE);
translationYAnim.setRepeatMode(ValueAnimator.INFINITE);
translationYAnim.start();
animators.add(translationYAnim);
AnimatorSet btnSexAnimatorSet = new AnimatorSet();
btnSexAnimatorSet.playTogether(animators);
btnSexAnimatorSet.setStartDelay(delay);
btnSexAnimatorSet.start();
}
開始設(shè)置setRepeatMode(ValueAnimator.INFINITE);
方法沒有效果胳嘲,只有設(shè)置setRepeatCount(ValueAnimator.INFINITE)
才可以了牛。
全科龍婷▼升職加薪