List of usage examples for android.view View getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:Main.java
public static void collapse(final View v) { final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override//w w w. java 2 s. c om 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
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; v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override//from www . j a va 2s. c o m 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 v, boolean isHalf) { v.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); targetHeight = v.getMeasuredHeight(); if (isHalf) { targetHeight = targetHeight / 2; }/*from w w w.j a v a 2 s .c om*/ // 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 Animation getCollapseViewAnimation(final View view, int duration) { final int initialHeight = view.getMeasuredHeight(); Animation animation = new Animation() { @Override//from w w w . jav a 2 s . 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
private static ValueAnimator slideAnimator(int start, int end, final View summary) { ValueAnimator animator = ValueAnimator.ofInt(start, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* w w w . j av a2 s . c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = summary.getLayoutParams(); layoutParams.height = value; summary.setLayoutParams(layoutParams); } }); return animator; }
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/*from w w w . j a v a 2 s. c o 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 void animateHeight(final View view, int from, int to, int duration) { boolean expanding = to > from; ValueAnimator anim = ValueAnimator.ofInt(from, to); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w w w. j av a 2 s. c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); layoutParams.height = val; view.setLayoutParams(layoutParams); } }); anim.setDuration(duration); anim.start(); view.animate().alpha(expanding ? 1 : 0).setDuration(duration / 2).start(); }
From source file:Main.java
public static void collapse(final View v, int duration) { //check if view already gone if (v.getVisibility() == View.GONE) return;/*ww w . j av a2 s.com*/ final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override 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(duration); v.startAnimation(a); }
From source file:Main.java
public static void collapse(final View v, boolean isHalf) { final int initialHeight = v.getMeasuredHeight(); remainHeigt = 0;/* ww w.j a v a 2 s .c o m*/ if (isHalf) { remainHeigt = initialHeight / 2; } else { remainHeigt = initialHeight; } Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime == 1) { v.setVisibility(View.GONE); } else { v.getLayoutParams().height = initialHeight - (int) (remainHeigt * 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 Animation collapse(final View v, int duration, boolean startAnim) { //check if view already gone if (v.getVisibility() == View.GONE) return null; final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override/*from w w w . ja 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(duration); if (startAnim) v.startAnimation(a); return a; }