Example usage for android.view.animation TranslateAnimation TranslateAnimation

List of usage examples for android.view.animation TranslateAnimation TranslateAnimation

Introduction

In this page you can find the example usage for android.view.animation TranslateAnimation TranslateAnimation.

Prototype

public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType,
        float fromYValue, int toYType, float toYValue) 

Source Link

Document

Constructor to use when building a TranslateAnimation from code

Usage

From source file:com.appassit.common.Utils.java

/**
 * ??/*from   w w w  .j a  va  2s.c  o m*/
 * 
 * @return
 */
public static LayoutAnimationController getLayoutAnimation() {
    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);
    set.addAnimation(animation);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(100);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    return controller;
}

From source file:com.smp.musicspeed.MainActivity.java

private void animateLinkOn() {

    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            -1.0f);//from   w ww.ja  v a  2 s.  com
    anim.setDuration(TRANS_ANIMATION_TIME);
    anim.setInterpolator(new AnticipateOvershootInterpolator());
    anim.setAnimationListener(new AnimationListenerAdaptor() {
        @Override
        public void onAnimationEnd(Animation animation) {
            rateText.setAlpha(0f);
            linkOn();

            rateText.animate().alpha(1f).setDuration(TRANS_ANIMATION_TIME)
                    .setListener(new AnimatorListenerAdapter() {
                    });
        }
    });
    tempoCard.startAnimation(anim);
    tempoText.animate().alpha(0f).setDuration(TEXT_ANIMATION_TIME).setListener(new AnimatorListenerAdapter() {
    });
}

From source file:de.grobox.transportr.trips.search.DirectionsFragment.java

private void swapLocations() {
    float toToY = fromCard.getY() - toCard.getY();
    Animation slideUp = new TranslateAnimation(RELATIVE_TO_SELF, 0.0f, RELATIVE_TO_SELF, 0.0f, RELATIVE_TO_SELF,
            0.0f, Animation.ABSOLUTE, toToY);
    slideUp.setDuration(400);// ww  w  .j  a  va 2s . c  om
    slideUp.setFillAfter(true);
    slideUp.setFillEnabled(true);

    float fromToY = toCard.getY() - fromCard.getY();
    Animation slideDown = new TranslateAnimation(RELATIVE_TO_SELF, 0.0f, RELATIVE_TO_SELF, 0.0f,
            RELATIVE_TO_SELF, 0.0f, Animation.ABSOLUTE, fromToY);
    slideDown.setDuration(400);
    slideDown.setFillAfter(true);
    slideDown.setFillEnabled(true);

    fromCard.startAnimation(slideDown);
    toCard.startAnimation(slideUp);

    slideUp.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // swap location objects
            WrapLocation tmp = to.getLocation();
            if (from.isSearching()) {
                viewModel.findGpsLocation.setValue(null);
                // TODO: GPS currently only supports from location, so don't swap it for now
                viewModel.setToLocation(null);
            } else {
                viewModel.setToLocation(from.getLocation());
            }
            viewModel.setFromLocation(tmp);

            fromCard.clearAnimation();
            toCard.clearAnimation();

            viewModel.search();
        }
    });
}

From source file:com.smp.musicspeed.MainActivity.java

private void animateLinkOff() {
    linkOff();//ww  w. ja  v  a  2  s.  c o m
    tempoCard.setVisibility(View.INVISIBLE);

    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            1.0f);
    anim.setDuration(TRANS_ANIMATION_TIME);
    anim.setInterpolator(new AnticipateOvershootInterpolator());
    anim.setAnimationListener(new AnimationListenerAdaptor() {
        @Override
        public void onAnimationEnd(Animation animation) {
            tempoText.setAlpha(0f);
            linkOff();

            tempoText.animate().alpha(1f).setDuration(TEXT_ANIMATION_TIME)
                    .setListener(new AnimatorListenerAdapter() {
                    });
        }
    });
    rateCard.startAnimation(anim);
    rateText.animate().alpha(0f).setDuration(TRANS_ANIMATION_TIME).setListener(new AnimatorListenerAdapter() {
    });
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWidget.java

public void goMySpace(View view) {
    addView(view);//from   ww w  . jav a  2  s. co m
    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(250);
    DecelerateInterpolator di = new DecelerateInterpolator();
    anim.setInterpolator(di);
    view.startAnimation(anim);
    mBroWindow.setVisibility(GONE);
}

From source file:com.example.fragment.PrimitiveFragment.java

public void move(float destX, float destY) {
    if (!this.mIsAlive)
        return;// www.ja v a 2s. c  om
    if (this.mIsMoving) {
        return;// ADD Array
    }
    this.mDestX = Factory.getAdjustedX(destX - this.mPaddingW);
    this.mDestY = Factory.getAdjustedY(destY - this.mPaddingH);
    // SELECT LAYER 
    FrameLayout relate = (FrameLayout) mRootView.findViewById(R.id.FLBackLayer);
    //       ScrollView relate = (ScrollView)mRootView.findViewById(R.id.content);
    //       relate.setVisibility(View.VISIBLE);

    AnimationSet set = new AnimationSet(true);
    set.setAnimationListener(this);

    TranslateAnimation translate;
    float toX = this.mDestX;
    float fromX = this.mSrcX;
    float toY = this.mDestY;
    float fromY = this.mSrcY;
    translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, fromX, Animation.RELATIVE_TO_PARENT, toX,
            Animation.RELATIVE_TO_PARENT, fromY, Animation.RELATIVE_TO_PARENT, toY);
    translate.setDuration(Constants.Animation.IPF);
    translate.setInterpolator(new AccelerateInterpolator());

    set.addAnimation(translate);
    set.setFillBefore(true);
    //          set.setFillBefore(false);
    //         set.setFillAfter(false);
    set.setFillAfter(true);

    relate.startAnimation(set);
    this.mIsMoving = true;
    this.mIsMove = true;
}

From source file:de.madvertise.android.sdk.MadvertiseView.java

private Animation createAnimation(final boolean isOutAnimation) {
    Animation animation = null;/*from   ww  w.  j  a v  a2 s. c om*/

    if (isOutAnimation) {
        if (mAnimationType != null && mAnimationType.equals(MadvertiseUtil.ANIMATION_TYPE_FADE)) {
            animation = new AlphaAnimation(1.0f, 0.0f);
            animation.setDuration(700);
        } else if (mAnimationType != null
                && mAnimationType.equals(MadvertiseUtil.ANIMATION_TYPE_LEFT_TO_RIGHT)) {
            animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
                    1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
            animation.setDuration(900);
            animation.setInterpolator(new AccelerateInterpolator());
        } else if (mAnimationType != null && mAnimationType.equals(MadvertiseUtil.ANIMATION_TYPE_TOP_DOWN)) {
            animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
                    0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
            animation.setDuration(900);
            animation.setInterpolator(new AccelerateInterpolator());
        }
    } else {
        if (mAnimationType != null && mAnimationType.equals(MadvertiseUtil.ANIMATION_TYPE_FADE)) {
            animation = new AlphaAnimation(0.0f, 1.0f);
            animation.setDuration(1200);
        } else if (mAnimationType != null
                && mAnimationType.equals(MadvertiseUtil.ANIMATION_TYPE_LEFT_TO_RIGHT)) {
            animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f);
            animation.setDuration(900);
            animation.setInterpolator(new AccelerateInterpolator());
        } else if (mAnimationType != null && mAnimationType.equals(MadvertiseUtil.ANIMATION_TYPE_TOP_DOWN)) {
            animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
                    0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
            animation.setDuration(900);
            animation.setInterpolator(new AccelerateInterpolator());
        }
    }

    // create a no-animation animation
    // if (animation == null) {
    // animation = new AlphaAnimation(1.0f, 1.0f);
    // }

    return animation;
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWidget.java

public boolean exitMySpace(View view) {
    if (view.getParent() == this) {
        mBroWindow.setVisibility(VISIBLE);
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 1.0f);
        anim.setDuration(300);// ww  w .  j  av  a 2s.  co m
        DecelerateInterpolator di = new DecelerateInterpolator();
        anim.setInterpolator(di);
        view.startAnimation(anim);
        removeView(view);
        return true;
    }
    return false;
}

From source file:com.turingtechnologies.materialscrollbar.MaterialScrollBar.java

/**
 * Provides the ability to programmatically alter whether the scrollbar
 * should hide after a period of inactivity or not.
 * @param hide sets whether the bar should hide or not.
 *///from  w  ww. ja  v  a  2s  .c  o m
public MaterialScrollBar setAutoHide(Boolean hide) {
    if (!hide) {
        fade.interrupt();
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        anim.setFillAfter(true);
        startAnimation(anim);
    } else if (!this.hide) {
        fade.start();
    }
    this.hide = hide;
    return this;
}