Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android property animation: how to increase view height?

How to increase the view height using Property Animations in Android?

ObjectAnimator a = ObjectAnimator.ofFloat(viewToIncreaseHeight, "translationY", -100); a.setInterpolator(new AccelerateDecelerateInterpolator()); a.setDuration(1000); a.start(); 

The translationY actually moves the view not increase the height. How can I increase the height of the view?

like image 513
g.revolution Avatar asked Sep 29 '15 03:09

g.revolution


People also ask

How do you animate visibility on Android?

The easiest way to animate Visibility changes is use Transition API which available in support (androidx) package. Just call TransitionManager. beginDelayedTransition method then change visibility of the view. There are several default transitions like Fade , Slide .

What is Property animation in Android?

A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.


2 Answers

ValueAnimator anim = ValueAnimator.ofInt(viewToIncreaseHeight.getMeasuredHeight(), -100); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {     @Override     public void onAnimationUpdate(ValueAnimator valueAnimator) {         int val = (Integer) valueAnimator.getAnimatedValue();         ViewGroup.LayoutParams layoutParams = viewToIncreaseHeight.getLayoutParams();         layoutParams.height = val;         viewToIncreaseHeight.setLayoutParams(layoutParams);     } }); anim.setDuration(DURATION); anim.start();  
like image 182
Rajan Kali Avatar answered Oct 17 '22 12:10

Rajan Kali


You can use ViewPropertyAnimator, which can save you some lines of code :

yourView.animate()    .scaleY(-100f)    .setInterpolator(new AccelerateDecelerateInterpolator())    .setDuration(1000); 

that should be all you need, be sure to check the documentation and all available methods for ViewPropertyAnimator.

like image 45
A Honey Bustard Avatar answered Oct 17 '22 11:10

A Honey Bustard