get Expand Bottom Animators - Android android.animation

Android examples for android.animation:Animator

Description

get Expand Bottom 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 {
    public static ArrayList<Animator> getExpandBottomAnimators(
            int[] center, int expandedWidth, int expandedHeight,
            ArrayList<View> items) {
        final ArrayList<Animator> animators = new ArrayList<>();
        if (items != null) {
            final float y = center[1] + expandedHeight / 2;
            for (int i = 0; i < items.size(); i++) {
                final float x = getDestinationX(center[0], expandedWidth,
                        items.get(i).getWidth(), items.size(), i);
                final ObjectAnimator translateX = ObjectAnimator.ofFloat(
                        items.get(i), "X", items.get(i).getX(), x);
                final ObjectAnimator translateY = ObjectAnimator.ofFloat(
                        items.get(i), "Y", items.get(i).getY(), y
                                - items.get(i).getHeight() / 2);
                animators.add(translateX);
                animators.add(translateY);
            }/*  w ww  .j  a v  a 2  s  . co m*/
        }
        return animators;
    }

    public static float getDestinationX(float centerX, int expandedWidth,
            int itemWidth, int itemSize, int item) {
        float x = (centerX - expandedWidth / 2)
                + (expandedWidth / itemSize * item + (expandedWidth
                        / itemSize * (item + 1) - expandedWidth / itemSize
                        * item) / 2) - itemWidth / 2;
        return x;
    }
}

Related Tutorials