blipinsk/ViewPropertyObjectAnimator

Duration is not working when changing height.

oscargrgm opened this issue · 2 comments

I'm trying to animate height changing and duration parameter is ignored. This is my code:

val height = View.MeasureSpec.makeMeasureSpec(this.height, View.MeasureSpec.EXACTLY)
ViewPropertyObjectAnimator.animate(this)
    .heightBy(0)
    .height(height)
    .setDuration(duration)
    .start()

The point is when I set final height to 0, it works perfectly:

val height = View.MeasureSpec.makeMeasureSpec(this.height, View.MeasureSpec.EXACTLY)
ViewPropertyObjectAnimator.animate(this)
    .heightBy(height)
    .height(0)
    .setDuration(duration)
    .start()

Any suggestion?

Hi @oscargrgm,
there are two things you are misusing:

  1. MeasureSpec is not a measure of height. It's something that "encapsulates the layout requirements passed from parent to child". It is used within the onMeasure method of the View. Read more here: https://developer.android.com/reference/android/view/View.MeasureSpec
  2. You're using heightBy and height at the same time which makes no sense. heightBy is a method to animate the height of a View by a particular height "diff". height animates View to an absolute value.

Resolve those two issues, and let me know if it helped or not. For now, I'm closing this issue.

Ok, you were right. I removed heightBy and now I'm getting the view's height in a different way an works perfectly. Thank you very much!