如何提高底部表格的高度遵循垂直翻译

发布于 2025-01-20 04:54:52 字数 553 浏览 2 评论 0原文

我正在尝试在bottosheetDialog中垂直移动视图,但是我会得到意外的行为。

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

如何动态地遵循BottomSheet的大小以遵循翻译?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百思不得你姐 2025-01-27 04:54:52

据我所知,您可以以编程方式更改BottomSheet的高度,在我的应用程序中,我正在使用以下代码来制作bottomSheet对话框。如果可能的话,屏幕:

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

因此,在您的情况下:

更改(int)(screenutils.getScreenheight())带有您的尺寸值。

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.

绿光 2025-01-27 04:54:52

我找到了解决这个问题的替代解决方案。我只是在布局底部添加了一个空视图,其高度为1DP。我正在增加这样的大小

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

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文