Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand a layout height with animation?

I couldn't find a good example for how to do this.

I have a RelativeLayout set with x height.

I want to add a button which expands the height to x+y height.

can someone refer me to a good example on how to do it programmatically?

like image 483
piojo Avatar asked Nov 09 '11 10:11

piojo


People also ask

How do you change the view height in animation?

How to increase the view height using Property Animations in Android? ObjectAnimator a = ObjectAnimator. ofFloat(viewToIncreaseHeight, "translationY", -100); a. setInterpolator(new AccelerateDecelerateInterpolator()); a.


1 Answers

You marked the solution that was closest. This is the exact solution. I had the same problem. Hopefully this answer will help others.

InstantiateResizeAnimation

ResizeAnimation resizeAnimation = new ResizeAnimation(      view,       targetHeight,       startHeight );  resizeAnimation.setDuration(duration);  view.startAnimation(resizeAnimation); 

ResizeAnimation class should look like this

public class ResizeAnimation extends Animation {     final int targetHeight;     View view;     int startHeight;      public ResizeAnimation(View view, int targetHeight, int startHeight) {         this.view = view;         this.targetHeight = targetHeight;         this.startHeight = startHeight;     }      @Override     protected void applyTransformation(float interpolatedTime, Transformation t) {         int newHeight = (int) (startHeight + targetHeight * interpolatedTime);         //to support decent animation, change new heigt as Nico S. recommended in comments         //int newHeight = (int) (startHeight+(targetHeight - startHeight) * interpolatedTime);         view.getLayoutParams().height = newHeight;         view.requestLayout();     }      @Override     public void initialize(int width, int height, int parentWidth, int parentHeight) {         super.initialize(width, height, parentWidth, parentHeight);     }      @Override     public boolean willChangeBounds() {         return true;     } } 
like image 56
the_prole Avatar answered Nov 03 '22 03:11

the_prole