Example usage for android.view View setVisibility

List of usage examples for android.view View setVisibility

Introduction

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

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:cn.aaronyi.ameneye.utils.AnimUtils.java

public static void scaleShow(View view, ViewPropertyAnimatorListener viewPropertyAnimatorListener) {
    view.setVisibility(View.VISIBLE);
    ViewCompat.animate(view).scaleX(1.0f).scaleY(1.0f).alpha(1.0f).setDuration(800)
            .setListener(viewPropertyAnimatorListener).setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).start();
}

From source file:Main.java

public static Animation expand(final View v, int duration, boolean startAnim) {
    if (v.getVisibility() == View.VISIBLE)
        return null;

    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    v.getLayoutParams().height = 0;/*ww w  .  j a  v  a 2 s . co m*/
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }

    };

    a.setDuration(duration);
    if (startAnim)
        v.startAnimation(a);
    return a;
}

From source file:Main.java

public static void expand(final View drawer) {
    drawer.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    final int targetHeight = drawer.getMeasuredHeight();

    //make the height of the draw 0px
    drawer.getLayoutParams().height = 0;
    //make it visible (no blink will occur since view has no height)
    drawer.setVisibility(View.VISIBLE);
    Animation anim = new Animation() {
        @Override/* w  w  w .j  a v a  2s  .c om*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            //1 means animation has completed
            drawer.getLayoutParams().height = interpolatedTime == 1 ? LinearLayout.LayoutParams.WRAP_CONTENT
                    //else height is a fraction of time remaining
                    : (int) (targetHeight * interpolatedTime);
            //force layout invalidation
            drawer.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            //return true since it will change bounds of view being animated
            return true;
        }
    };

    anim.setDuration(ANIMATION_DURATION_SHORT);
    drawer.startAnimation(anim);
}

From source file:Main.java

private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer,
        final int targtetHeight) {

    setHeight(view, 0);/*from   w  w  w  . j  a v a  2 s .  c om*/
    view.setVisibility(View.VISIBLE);
    final Animation animation = new Animation() {

        private final Rect rect = new Rect();
        private final Rect parentVisibleRect = new Rect();

        ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener;

        private final Runnable checkViewRunnable = new Runnable() {
            @Override
            public void run() {
                checkForViewInsideVisibleArea();
            }
        };

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            setHeight(view, neededHeight);

            final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();

            if (globalLayoutListener == null) {
                globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

                    @Override
                    public void onGlobalLayout() {

                        if (globalLayoutListener == null) {
                            removeGlobalLayoutListener(viewTreeObserver, this);
                        }

                        checkForViewInsideVisibleArea();
                    }
                };

                viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener);
            }

            if (globalLayoutListener != null && interpolatedTime == 1) {
                runInUIThread(checkViewRunnable);
                globalLayoutListener = null;
            }

            view.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }

        private void checkForViewInsideVisibleArea() {

            if (rootContainer.indexOfChild(parentView) == -1) {
                return;
            }

            parentVisibleRect.left = 0;
            parentVisibleRect.top = 0;
            parentVisibleRect.right = parentView.getWidth();
            parentVisibleRect.bottom = parentView.getHeight();

            rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect);

            if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) {

                rect.left = parentView.getLeft();
                rect.top = parentView.getTop();
                rect.right = parentView.getRight();
                rect.bottom = parentView.getBottom();

                parentView.requestRectangleOnScreen(rect, true);
            }
        }
    };

    animation.setDuration(ANIMATION_DURATION);
    view.startAnimation(animation);
}

From source file:Main.java

public static void showViewAlphaAnim(final View view, TimeInterpolator interpolator, final boolean visible) {
    if (visible && view.getVisibility() == View.VISIBLE || !visible && view.getVisibility() != View.VISIBLE) {
        return;/*from www.  ja va  2s.  c  o m*/
    }

    float fromAlpha = visible ? 0.0F : 1.0F;
    float toAlpha = visible ? 1.0F : 0.0F;
    view.setAlpha(fromAlpha);
    view.setVisibility(View.VISIBLE);
    view.animate().alpha(toAlpha).setDuration(DURATION).setInterpolator(interpolator)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    if (visible) {
                        view.setAlpha(1.0F);
                        view.setVisibility(View.VISIBLE);
                    } else {
                        view.setAlpha(0.0F);
                        view.setVisibility(View.INVISIBLE);
                    }
                }
            }).start();
}

From source file:Main.java

public static void updateTextViewIconRight(Context context, View view, int resourceId) {
    if (view != null && view instanceof TextView) {
        Drawable drawable = context.getResources().getDrawable(resourceId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        ((TextView) view).setCompoundDrawables(null, null, drawable, null);
        ((TextView) view).setCompoundDrawablePadding(2);
        view.setVisibility(View.VISIBLE);
    }/*from   ww  w .ja va2  s  .co  m*/
}

From source file:Main.java

public static void startFadeInAnimationOn(final View container, boolean forceFade) {
    if (forceFade || container.getVisibility() != View.VISIBLE) {
        Animation animation = getFadeInAnimation(FADE_DURATION);
        animation.setAnimationListener(new AnimationListener() {
            @Override/*from w  w  w  .  jav a 2  s  .  c  o m*/
            public void onAnimationStart(Animation animation) {
                container.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
            }
        });

        container.startAnimation(animation);
    }
}

From source file:Main.java

/**
 * Fade in a view with the default time//from  w  ww .  j  a  v  a2s . co  m
 * @param view The {@link View} to use
 */
public static void fadeOut(View view) {
    if (view.getVisibility() != View.VISIBLE)
        return;

    // Since the button is still clickable before fade-out animation
    // ends, we disable the button first to block click.
    view.setEnabled(false);
    Animation animation = new AlphaAnimation(1F, 0F);
    animation.setDuration(400);
    view.startAnimation(animation);
    view.setVisibility(View.GONE);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static ViewPropertyAnimator fadeOut(final View from, int duration) {
    if (from.getVisibility() == View.VISIBLE) {
        from.clearAnimation();//w  w  w. j  a v  a2s  .c o  m
        final ViewPropertyAnimator animator = from.animate();
        animator.alpha(0f).setDuration(duration).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                from.setVisibility(View.INVISIBLE);
                from.setAlpha(1f);
            }
        });
        return animator;
    }
    return null;
}

From source file:Main.java

public static void animateScaleIn(final View view) {
    view.animate().setStartDelay(100).alpha(0).scaleX(0f).scaleY(0f)
            .setListener(new Animator.AnimatorListener() {
                @Override/*  w  ww  . j  a v  a  2  s .c o  m*/
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    view.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
}