动态更改BottomSheetBehavior的高度 [英] Dynamically change height of BottomSheetBehavior

查看:2306
本文介绍了动态更改BottomSheetBehavior的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google最近发布的AppCompat v23.2中的BottomSheetBehavior.我底部的高度取决于底部内部显示的内容(类似于Google在自己的地图"应用中所做的操作.

它可以很好地处理最初加载的数据,但是我的应用程序会更改运行时显示的内容,并且当这种情况发生时,底部工作表会保留其旧高度,这会导致底部的未使用空间或视图的切开./p>

是否有任何方法可以通知底部工作表布局以重新计算用于展开状态的高度(当ViewGroup的高度设置为MATCH_HEIGHT时)还是可以手动设置所需的高度?


编辑:我还尝试在ViewGroup及其父级上手动调用invalidate(),但未成功.

解决方案

RelativeLayout一样,我遇到了同样的问题.高度不会重新计算.我不得不求助于通过新的重新计算的值来设置高度,然后调用BottomSheetBehavior.onLayoutChild.

这是我的临时解决方案:

coordinatorLayout = (CoordinatorLayout)findViewById(R.id.coordinator_layout);
bottomSheet = findViewById(R.id.bottom_sheet);

int accountHeight = accountTextView.getHeight();
accountTextView.setVisibility(View.GONE);

bottomSheet.getLayoutParams().height = bottomSheet.getHeight() - accountHeight;
bottomSheet.requestLayout();
behavior.onLayoutChild(coordinatorLayout, bottomSheet, ViewCompat.LAYOUT_DIRECTION_LTR);

I'm using the BottomSheetBehavior from Google recently released AppCompat v23.2. The height of my bottom sheet depends on the content displayed inside of the bottom sheet (similar to the what Google does themselves in their Maps app).

It works fine with the data loaded initially, but my application changes the content displayed during runtime and when this happens the bottom sheet retains at it's old height, which either leads to unused space at the bottom or a cut of view.

Is there any way to inform the bottom sheet layout to recalculate the height used for expanded state (when height of the ViewGroup is set to MATCH_HEIGHT) or any way to manually set the required height?


EDIT: I also tried to manually call invalidate() on the ViewGroup and the parent of it but without any success.

解决方案

I had the same problem with RelativeLayout as my bottom sheet. The height won't be recalculated. I had to resort to setting the height by the new recalculated value and call BottomSheetBehavior.onLayoutChild.

This is my temporary solution:

coordinatorLayout = (CoordinatorLayout)findViewById(R.id.coordinator_layout);
bottomSheet = findViewById(R.id.bottom_sheet);

int accountHeight = accountTextView.getHeight();
accountTextView.setVisibility(View.GONE);

bottomSheet.getLayoutParams().height = bottomSheet.getHeight() - accountHeight;
bottomSheet.requestLayout();
behavior.onLayoutChild(coordinatorLayout, bottomSheet, ViewCompat.LAYOUT_DIRECTION_LTR);

这篇关于动态更改BottomSheetBehavior的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆