Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid smooth width change animation
    text
    copied!<p>Have anybody know how to implement a smooth width-change animation on Android? I've checked several examples with custom Animation class, or by ValueAnimator+AnimatorUpdateListener - but their work is not smooth, especially when there are several additional animations on the same time working on. </p> <p>Any ideas? Thanks</p> <p>I'm animating items in the list with next code (it's not smooth with even 4 items), also sometimes with them occurs animation with translation of a view from top to bottom - and it is also not smooth (but if the translation animation work without list items width change - it's smooth):</p> <pre><code> public void showDragHold() { isOnDrag = true; int width = -1; int duration = 0; LinkedList&lt;Animator&gt; valueAnimators = new LinkedList&lt;Animator&gt;(); for (View view : views) { View dragView = view.findViewById(R.id.list_handle_drag); if (width &lt; 0) { width = dragView.getResources().getDimensionPixelSize(R.dimen.drag_width); duration = dragView.getResources().getInteger(R.integer.anim_fast_duration); } ValueAnimator valueAnimator = ValueAnimator.ofInt(0, width); valueAnimator.addUpdateListener(new ResizeUpdateAnimator(dragView)); valueAnimators.add(valueAnimator); } if (!valueAnimators.isEmpty()) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(valueAnimators); animatorSet.setDuration(duration); animatorSet.start(); } } private static final class ResizeUpdateAnimator implements ValueAnimator.AnimatorUpdateListener { private View view; public ResizeUpdateAnimator(View view) { this.view = view; } @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { final int newWidth = (Integer) valueAnimator.getAnimatedValue(); view.getLayoutParams().width = newWidth; view.requestLayout(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload