animate View From Bottom - Android User Interface

Android examples for User Interface:View Translate

Description

animate View From Bottom

Demo Code

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.LinearLayout.LayoutParams;

public class Main {
  public static void animateViewFromBottom(View viewToAnimate, ViewGroup parentView) {
    parentView.addView(viewToAnimate);//from w  w  w .  java2s.  c o m
    LayoutParams params = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    viewToAnimate.setLayoutParams(params);

    int height = parentView.getHeight();
    viewToAnimate.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    int targetY = height / 2 - viewToAnimate.getMeasuredHeight() / 2;

    viewToAnimate.setTranslationY(height);
    viewToAnimate.animate().y(targetY).setInterpolator(new OvershootInterpolator(2F)).setDuration(400).start();
  }
}

Related Tutorials