一个发散动画的菜单控件(主要记录控件x,y坐标的运动状况)

 private void showCloseAnim() {
        int size = viewList.size();
        if (size % 2 == 0) {
            //是偶数
            for (int i = 0; i < size; i++) {
                if (i < size / 2) {
                    //坐标轴下边
                    AnimatorSet set = new AnimatorSet();
                    double x = -Math.cos(Math.PI * (size - 1 - 2 * i) / (4 * size - 4)) * 600;
                    double y = Math.sin(Math.PI * (size - 1 - 2 * i) / (4 * size - 4)) * 600;
                    set.playTogether(ObjectAnimator.ofFloat(viewList.get(i), "translationX", (float) x, 0),
                            ObjectAnimator.ofFloat(viewList.get(i), "translationY", (float) y, 0));
                    set.setInterpolator(new BounceInterpolator());
                    set.setDuration(500).setStartDelay(100 * i);
                    set.start();
                    
                } else {
                    //坐标轴上边
                    AnimatorSet set = new AnimatorSet();
                    double x = -Math.cos(Math.PI * (2 * i - size + 1) / (4 * size - 4)) * 600;
                    double y = -Math.sin(Math.PI * (2 * i - size + 1) / (4 * size - 4)) * 600;
                    set.playTogether(ObjectAnimator.ofFloat(viewList.get(i), "translationX", (float) x, 0),
                            ObjectAnimator.ofFloat(viewList.get(i), "translationY", (float) y, 0));
                    set.setDuration(500).setStartDelay(100 * i);
                    set.start();
                }
            }
            
            
        } else {
            //是奇数
        }
    }
    
    private void showOpenAnim() {
        int size = viewList.size();
        if (size % 2 == 0) {
            //是偶数
            for (int i = 0; i < size; i++) {
                if (i < size / 2) {
                    //坐标轴下边
                    AnimatorSet set = new AnimatorSet();
                    double x = -Math.cos(Math.PI * (size - 1 - 2 * i) / (4 * size - 4)) * 600;
                    double y = Math.sin(Math.PI * (size - 1 - 2 * i) / (4 * size - 4)) * 600;
                    set.playTogether(ObjectAnimator.ofFloat(viewList.get(i), "translationX", 0, (float) x),
                            ObjectAnimator.ofFloat(viewList.get(i), "translationY", 0, (float) y),
                            ObjectAnimator.ofFloat(viewList.get(i), "alpha", 0, 1).setDuration(2000));
                    set.setDuration(500).setStartDelay(100 * i);
                    set.start();
                    
                } else {
                    //坐标轴上边
                    AnimatorSet set = new AnimatorSet();
                    double x = -Math.cos(Math.PI * (2 * i - size + 1) / (4 * size - 4)) * 600;
                    double y = -Math.sin(Math.PI * (2 * i - size + 1) / (4 * size - 4)) * 600;
                    set.playTogether(ObjectAnimator.ofFloat(viewList.get(i), "translationX", 0, (float) x),
                            ObjectAnimator.ofFloat(viewList.get(i), "translationY", 0, (float) y),
                            ObjectAnimator.ofFloat(viewList.get(i), "alpha", 0, 1).setDuration(2000));
                    set.setDuration(500).setStartDelay(100 * i);
                    set.start();
                }
            }
            
            
        } else {
            //是奇数
        }
    }
原文地址:https://www.cnblogs.com/yegong0214/p/9364363.html