Home > Mobile >  How to increase the height of a BottomSheetDialog to follow a vertical translation
How to increase the height of a BottomSheetDialog to follow a vertical translation

Time:04-09

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?

CodePudding user response:

As far as I know, you can change the height of the BottomSheet programmatically, in my application, I'm using the following code to make the BottomSheet dialog take the height of the screen if possible:

BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) sheetView.getParent());
mBehavior.setPeekHeight((int) (ScreenUtils.getScreenHeight()));

So in your case :

Change (int) (ScreenUtils.getScreenHeight()) with your size value.

CodePudding user response:

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()
  • Related