I am trying to resize a view to fit a different view size using ValueAnimator. I use it instead of animation because I need the view to be available after clicking.
private Animator getHeightScaleAnimator(View target) {
ConstraintLayout.LayoutParams thisParams = (ConstraintLayout.LayoutParams) getLayoutParams();
ConstraintLayout.LayoutParams targetParams = (ConstraintLayout.LayoutParams) target.getLayoutParams();
int currentHeight = thisParams.height;
int desiredHeight = targetParams.height;
ValueAnimator animator = ValueAnimator.ofInt(currentHeight, desiredHeight);
animator.addUpdateListener(animation -> {
int newInt = (int) animation.getAnimatedValue();
thisParams.width = newInt;
invalidate();
requestLayout();
});
return animator;
}
The code above shows a method in which I am trying to increase the height of the view to the required height of the view, and I have the same method for the width, but with the width instead of the height.
The desired behavior was the view, in order to increase its size until it reaches the target view, but for some odd reason, the view moves instead of resizing.
The implementation class is an extension of ImageView, but the method from ImageView has not been changed.
, ?