List of usage examples for android.view View requestLayout
@CallSuper public void requestLayout()
From source file:Main.java
public static Animation getExpandViewAnimation(final View view, int duration) { view.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); final int targetHeight = view.getMeasuredHeight(); view.getLayoutParams().height = 0;// w w w.jav a 2s . c o m view.setVisibility(View.VISIBLE); Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms // animation.setDuration((int) (targetHeight / // view.getContext().getResources().getDisplayMetrics().density)); animation.setDuration(duration); return animation; }
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 . c o 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
/** * Animates a view to the new specified dimensions. * @param view The view to change the dimensions of. * @param newWidth The new width of the view. * @param newHeight The new height of the view. *//*from ww w . jav a 2s. c om*/ public static void changeDimensions(final View view, final int newWidth, final int newHeight) { ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); final int oldWidth = view.getWidth(); final int oldHeight = view.getHeight(); final int deltaWidth = newWidth - oldWidth; final int deltaHeight = newHeight - oldHeight; animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { Float value = (Float) animator.getAnimatedValue(); view.getLayoutParams().width = (int) (value * deltaWidth + oldWidth); view.getLayoutParams().height = (int) (value * deltaHeight + oldHeight); view.requestLayout(); } }); animator.start(); }
From source file:Main.java
public static void expand(final View v, boolean isHalf) { v.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); targetHeight = v.getMeasuredHeight(); if (isHalf) { targetHeight = targetHeight / 2; }/*from ww w . ja v a2s . c o m*/ // Older versions of android (pre API 21) cancel animations for views with a height of 0. v.getLayoutParams().height = 1; v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.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, Activity activity) { v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); Resources r = activity.getResources(); final float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, r.getDisplayMetrics()); final int targtetHeight = (int) px;//200;//v.getMeasuredHeight(); v.getLayoutParams().height = 0;// 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 ? ((int) px)//200//ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(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 2 s . com*/ 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:nkarasch.repeatingreminder.gui.AlertView.java
private static void collapseView(final View view) { final int initialHeight = view.getMeasuredHeight(); Animation animation = new Animation() { @Override//from w w w . j av a 2 s . c o m protected void applyTransformation(float interpolatedTime, Transformation transformation) { 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((int) (initialHeight / view.getContext().getResources().getDisplayMetrics().density)); view.startAnimation(animation); }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Resize a view height and request the re-draw of the view * * @param viewToResize Main Screen Windows to * @param height Amount of pixel can be seeing * @param addValue true increase size else decrease *//*from www . ja v a 2 s . c o m*/ private static void resizeViewHeight(View viewToResize, int height, boolean addValue, int realScreenHeight) { if (addValue) { viewToResize.getLayoutParams().height = viewToResize.getHeight() + height; } else { viewToResize.getLayoutParams().height = realScreenHeight - height; } viewToResize.requestLayout(); }
From source file:nkarasch.repeatingreminder.gui.AlertView.java
private static void expandView(final View view) { view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final int targetHeight = view.getMeasuredHeight(); view.getLayoutParams().height = 0;//from w w w. j a v a2s. c o m view.setVisibility(View.VISIBLE); Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration((int) (targetHeight / view.getContext().getResources().getDisplayMetrics().density)); view.startAnimation(animation); }
From source file:com.develop.autorus.MainActivity.java
public static void collapse(final View v) { final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override//from w w w . jav 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((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }