// 开始动画 private void startAnim() { // 遍历第一个不是主菜单的ImageView列表 for (int i = 1; i < res.length; i++) { // 获取展开角度 float angle = (90 * 1.0f / (res.length - 2)) * (i - 1); // 获取X位移 PropertyValuesHolder holder1 = PropertyValuesHolder.ofFloat( "translationX", 0, (float) (Math.sin((angle * 1.57 / 90)) * 200)); // 获取Y位移 PropertyValuesHolder holder2 = PropertyValuesHolder.ofFloat( "translationY", 0, (float) (Math.cos((angle * 1.57 / 90)) * 200)); // 设置ImageView的属性动画 ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageViewList.get(i), holder1, holder2); // ObjectAnimator animator = // ObjectAnimator.ofFloat(imageViewList.get(i), "translationY", 0, i * // 60); // 动画时间 animator.setDuration(1000); // 动画延迟时间 animator.setFrameDelay(500 * i); // 设置加速器 animator.setInterpolator(new BounceInterpolator()); // 启动动画 animator.start(); isNotExpand = false; } }
public MyAnimationView(Context context) { super(context); ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", RED, BLUE); colorAnim.setDuration(3000); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); ObjectAnimator.setFrameDelay(0); colorAnim.start(); }