Example usage for android.view View requestLayout

List of usage examples for android.view View requestLayout

Introduction

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

Prototype

@CallSuper
public void requestLayout() 

Source Link

Document

Call this when something has changed which has invalidated the layout of this view.

Usage

From source file:Main.java

public static void animCollapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override/*  w  ww  .  j a  v  a2 s .  co m*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

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

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override//  w ww  .  j av  a2 s. co  m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

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

    // 1dp/ms
    a.setDuration(1000);
    // a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation() {
        @Override/*  ww  w .  j  a v  a  2 s .c o m*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

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

    a.setDuration(300);
    v.startAnimation(a);
}

From source file:Main.java

private static Animation collapseAnimation(final View drawer) {
    final int initialHeight = drawer.getMeasuredHeight();

    return new Animation() {
        @Override//from ww  w  . j  av a  2  s . com
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                drawer.setVisibility(View.GONE);
            } else {
                drawer.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                drawer.requestLayout();
            }
        }

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

From source file:Main.java

public static void moveByAmount(View viewToMove, int amount) {
    Integer viewHeight = viewToMove.getHeight();
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) viewToMove.getLayoutParams();
    if (params.topMargin + amount < viewHeight * -1) {
        params.topMargin = viewHeight * -1;
    } else if (params.topMargin + amount > 0) {
        params.topMargin = 0;/*from w  w  w .java2s .com*/
    } else {
        params.topMargin = params.topMargin + amount;
    }
    viewToMove.setLayoutParams(params);
    viewToMove.requestLayout();
}

From source file:Main.java

public static void expand(final View v, final int targetHeight, int duration, Interpolator interpolator,
        final Animation.AnimationListener listener) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation() {
        @Override//  w ww .j  av a 2 s. co  m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = initialHeight + (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(duration);
    if (interpolator != null) {
        a.setInterpolator(interpolator);
    }
    a.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (listener != null)
                listener.onAnimationStart(animation);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            v.setLayerType(View.LAYER_TYPE_NONE, null);
            if (listener != null)
                listener.onAnimationEnd(animation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            if (listener != null)
                onAnimationRepeat(animation);
        }
    });

    v.startAnimation(a);
}

From source file:Main.java

public static Animation getCollapseViewAnimation(final View view, int duration) {
    final int initialHeight = view.getMeasuredHeight();

    Animation animation = new Animation() {
        @Override//from w  w w.  j  ava2s  .  c o  m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                view.setVisibility(View.GONE);
            } else {
                view.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                view.requestLayout();
            }
        }

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

    animation.setDuration(duration);
    return animation;
}

From source file:Main.java

public static void animExpand(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

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

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

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void expand(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targtetHeight = v.getMeasuredHeight();

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

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

    // 1dp/ms
    a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

static void changeViewLeftPadding(final View view, int fromMargin, int toMargin) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromMargin, toMargin);
    animator.setDuration(3000);//from   w  w  w  .  j a v a 2  s .com
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            view.setPadding((int) animatedValue, view.getPaddingTop(), view.getPaddingRight(),
                    view.getPaddingBottom());
            view.requestLayout();

        }
    });
    animator.start();
}