get Collapse Animators - Android android.animation

Android examples for android.animation:Animator

Description

get Collapse Animators

Demo Code


//package com.java2s;
import android.animation.Animator;

import android.animation.ObjectAnimator;

import android.view.View;

import java.util.ArrayList;

public class Main {
    @SafeVarargs//from w  ww.j  a v a 2  s .  c  o m
    public static ArrayList<Animator> getCollapseAnimators(int[] center,
            ArrayList<View>... items) {
        final ArrayList<Animator> animators = new ArrayList<>();
        if (items != null && items.length > 0) {
            for (ArrayList<View> item : items) {
                if (item != null) {
                    for (View view : item) {
                        final ObjectAnimator translateX = ObjectAnimator
                                .ofFloat(view, "X", view.getX(), center[0]
                                        - view.getWidth() / 2);
                        final ObjectAnimator translateY = ObjectAnimator
                                .ofFloat(view, "Y", view.getY(), center[1]
                                        - view.getHeight() / 2);
                        animators.add(translateX);
                        animators.add(translateY);
                    }
                }
            }
        }
        return animators;
    }
}

Related Tutorials