sau*_*lon 6 android bottom-sheet
问题是上述问题的扩展,我想根据屏幕尺寸动态设置工作表的最大展开高度。
我已经尝试为实现底部表行为的视图设置新的布局参数,但它没有任何好处。
sau*_*lon -4
终于找到了,
这个问题让我很困扰,没有任何解决方案报告,答案就在于行为本身。
最小偏移量是底片应移动到的最大值,我们将该值的下限设置为我们希望底片移动到的所需高度。您可以公开一个函数来设置值或直接在我们的行为中执行此操作。
要动态设置底片的最大展开高度,我们需要在 BottomSheetBehavior 类中将最小偏移值从 0 增加到所需值,让我展示代码。
快乐编码!!
// The minimum offset value upto which your bottomsheet to move
private int mMinOffset;
/**
* Called when the parent CoordinatorLayout is about the layout the given child view.
*/
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
int dynamicHeight = Utils.dpToPx(parent.getContext(), **your_value_in_dp**);
mMinOffset = Math.max(dynamicHeight, mParentHeight - child.getHeight());
mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);
mAnchorOffset = Math.min(mParentHeight - mAnchorHeight, mMaxOffset);
if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
anchorViews(mMinOffset);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7832 次 |
最近记录: |