Search code examples
androidandroid-layoutandroid-animationandroid-transitions

How to increase the height of a BottomSheetDialog to follow a vertical translation


I'm trying to move views vertically in a BottoSheetDialog, but I'm getting an unexpected behavior.

My BottomSheet looks like this

Before Translation

I'm moving my constraint Layout with myLayout.animate().translationY(-100f).setStartDelay(0).start()

That's the BottomSheet after the translation:

After Transition

How can I increase the size of the BottomSheet dynamically to follow the translation?


Solution

  • I found an alternative solution to solve this problem. I just added a empty view with 1dp height at the Bottom of my layout. I'm increasing it's size like this

    val anim = ValueAnimator.ofInt(AnimationView.measuredHeight, 100)
    anim.addUpdateListener()
    {
         valueAnimator ->
         val value = valueAnimator.animatedValue as Int
         val layoutParams: ViewGroup.LayoutParams = AnimationView.layoutParams
         layoutParams.height = value
         AnimationView.layoutParams = layoutParams
     }
     anim.duration = 500
     anim.start()