Example usage for android.view View setAlpha

List of usage examples for android.view View setAlpha

Introduction

In this page you can find the example usage for android.view View setAlpha.

Prototype

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) 

Source Link

Document

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Usage

From source file:Main.java

public static void fadeOutView(final View view) {
    view.animate().alpha(0f).setListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            view.setVisibility(View.INVISIBLE);
            view.setAlpha(1f);
            view.animate().setListener(null);
        }/*w w  w .ja v a2 s  .c  o  m*/
    });
}

From source file:Main.java

public static void crossFadeViews(final Context context, final View fadeInView, final View fadeOutView) {
    long shortDuration = context.getResources().getInteger(android.R.integer.config_shortAnimTime);

    //fadeInView should initially be transparent but visible
    fadeInView.setAlpha(0f);
    fadeInView.setVisibility(View.VISIBLE);

    //animate fadeInView from 0f to 1f
    ViewCompat.animate(fadeInView).alpha(1f).setDuration(shortDuration).withLayer();

    //animate fadeOutView from 1f to 0f
    ViewCompat.animate(fadeOutView).alpha(0f).withLayer().withEndAction(new Runnable() {
        @Override/*from  w w  w . ja  v  a 2 s  .  c o  m*/
        public void run() {
            fadeOutView.setVisibility(View.GONE);
        }
    });
}

From source file:com.erevacation.challenge.rxjavaanimator.ViewAnimatorCreator.java

private static ViewPropertyAnimator animateFadeIn(View view, int duration, int delay,
        TimeInterpolator interpolator) {
    view.setAlpha(0);
    ViewPropertyAnimator propertyAnimator = view.animate().alpha(1).setStartDelay(delay).setDuration(duration);
    if (interpolator != null) {
        propertyAnimator.setInterpolator(interpolator);
    } else {/*w ww.  j  av  a  2s . c  o m*/
        propertyAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    }

    return propertyAnimator;
}

From source file:com.erevacation.challenge.rxjavaanimator.ViewAnimatorCreator.java

private static ViewPropertyAnimator animateFadeOut(View view, int duration, int delay,
        TimeInterpolator interpolator) {
    view.setAlpha(1);
    ViewPropertyAnimator propertyAnimator = view.animate().alpha(0).setStartDelay(delay).setDuration(duration);
    if (interpolator != null) {
        propertyAnimator.setInterpolator(interpolator);
    } else {//  www .ja  v  a2  s  .c om
        propertyAnimator.setInterpolator(new FastOutLinearInInterpolator());
    }

    return propertyAnimator;
}

From source file:Main.java

public static void fadeOut(final View view, final AnimatorListenerAdapter listener) {
    view.animate().alpha(0).setListener(new AnimatorListenerAdapter() {
        @Override/*from w ww . j  a va  2  s  .co m*/
        public void onAnimationEnd(Animator animation) {
            listener.onAnimationEnd(animation);
            view.setAlpha(1f);
        }
    });

}

From source file:Main.java

public static void animatePhotoLike(final View vBgLike, final View ivLike) {
    vBgLike.setVisibility(View.VISIBLE);
    ivLike.setVisibility(View.VISIBLE);

    vBgLike.setScaleY(0.1f);/*from ww w  .  j av a  2s .  c  om*/
    vBgLike.setScaleX(0.1f);
    vBgLike.setAlpha(1f);
    ivLike.setScaleY(0.1f);
    ivLike.setScaleX(0.1f);

    android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet();

    android.animation.ObjectAnimator bgScaleYAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleY",
            0.1f, 1f);
    bgScaleYAnim.setDuration(200);
    bgScaleYAnim.setInterpolator(DECELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgScaleXAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleX",
            0.1f, 1f);
    bgScaleXAnim.setDuration(200);
    bgScaleXAnim.setInterpolator(DECELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgAlphaAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "alpha",
            1f, 0f);
    bgAlphaAnim.setDuration(200);
    bgAlphaAnim.setStartDelay(150);
    bgAlphaAnim.setInterpolator(DECELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleUpYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 0.1f, 1f);
    imgScaleUpYAnim.setDuration(300);
    imgScaleUpYAnim.setInterpolator(DECELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleUpXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 0.1f, 1f);
    imgScaleUpXAnim.setDuration(300);
    imgScaleUpXAnim.setInterpolator(DECELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleDownYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 1f, 0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleDownXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 1f, 0f);
    imgScaleDownXAnim.setDuration(300);
    imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);

    animatorSet.addListener(new android.animation.AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            vBgLike.setVisibility(View.INVISIBLE);
            ivLike.setVisibility(View.INVISIBLE);
        }
    });
    animatorSet.start();
}

From source file:Main.java

public static void animatePhotoLike(final View vBgLike, final View ivLike) {
    vBgLike.setVisibility(View.VISIBLE);
    ivLike.setVisibility(View.VISIBLE);

    vBgLike.setScaleY(0.1f);/*from w w  w . ja v a2s . c om*/
    vBgLike.setScaleX(0.1f);
    vBgLike.setAlpha(1f);
    ivLike.setScaleY(0.1f);
    ivLike.setScaleX(0.1f);

    android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet();

    android.animation.ObjectAnimator bgScaleYAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleY",
            0.1f, 1f);
    bgScaleYAnim.setDuration(200);
    bgScaleYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgScaleXAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleX",
            0.1f, 1f);
    bgScaleXAnim.setDuration(200);
    bgScaleXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgAlphaAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "alpha",
            1f, 0f);
    bgAlphaAnim.setDuration(200);
    bgAlphaAnim.setStartDelay(150);
    bgAlphaAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleUpYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 0.1f, 1f);
    imgScaleUpYAnim.setDuration(300);
    imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleUpXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 0.1f, 1f);
    imgScaleUpXAnim.setDuration(300);
    imgScaleUpXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleDownYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 1f, 0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleDownXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 1f, 0f);
    imgScaleDownXAnim.setDuration(300);
    imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);

    animatorSet.addListener(new android.animation.AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            vBgLike.setVisibility(View.INVISIBLE);
            ivLike.setVisibility(View.INVISIBLE);
        }
    });
    animatorSet.start();
}

From source file:Main.java

@SuppressLint("NewApi")
public static void setAlpha(View view, float alpha) {
    if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(0);/*w  w  w .ja v  a2 s.  c om*/
        animation.setFillAfter(true);
        view.startAnimation(animation);
    } else {
        view.setAlpha(alpha);
    }
}

From source file:me.lizheng.deckview.helpers.DeckChildViewTransform.java

/**
 * Reset the transform on a view.// w w w.j a  va  2 s.  c o m
 */
public static void reset(View v) {
    v.setTranslationX(0f);
    v.setTranslationY(0f);
    ViewCompat.setTranslationZ(v, 0f);
    v.setScaleX(1f);
    v.setScaleY(1f);
    v.setAlpha(1f);
}

From source file:Main.java

public static void show(final View view) {
    if (Build.VERSION.SDK_INT >= 11) {
        final Animation animation = new Animation() {
            @TargetApi(11)//from   ww w .  j  ava2  s .com
            @Override
            protected void applyTransformation(final float interpolatedTime, final Transformation t) {
                view.setAlpha(interpolatedTime);
            }
        };

        animation.setDuration(ANIMATION_DURATION);
        // return animation;
        view.startAnimation(animation);
    } else {
        view.setVisibility(View.VISIBLE);
    }
}