android - BottomSheetDialogFragment 打开一半
问题描述
BottomSheetDialogFragment
当我打开它时,我打开了一半(意思是没有完全打开)。
fragment.show(supportFragmentManager, "my_frag")
- 我试过但没有
NestedScrollView
用。behavior_peekHeight
- 试过没有
NestedScrollView
。只有LinearLayout
. match_parent
尝试在&之间切换高度wrap_content
我RecyclerView
的BottomSheetDialogFragment
布局很简单。
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
...
>
<android.support.v7.widget.RecyclerView
...
/>
解决方案
BottomSheetFragment
你的意思BottomSheetDialogFragment
是。要打开已使用的工作表,您需要在onCreateDialog()
.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog bottomSheetDialog=(BottomSheetDialog)super.onCreateDialog(savedInstanceState);
bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
BottomSheetDialog dialog = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = dialog .findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
BottomSheetBehavior.from(bottomSheet).setHideable(true);
}
});
return bottomSheetDialog;
}
只需保持布局match_parent
不需要使用NestedScrollView
. 它对我有用。如果您仍然遇到问题,请告诉我。
万一有人在使用新材料库。这是
implementation 'com.google.android.material:material:1.0.0'
。然后你需要改变 Parent 的 id FrameLayout
。所以会的。
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog bottomSheetDialog=(BottomSheetDialog)super.onCreateDialog(savedInstanceState);
bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dia) {
BottomSheetDialog dialog = (BottomSheetDialog) dia;
FrameLayout bottomSheet = dialog .findViewById(com.google.android.material.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
BottomSheetBehavior.from(bottomSheet).setHideable(true);
}
});
return bottomSheetDialog;
}
import com.google.android.material
在这种情况下,请确保您的所有导入。
推荐阅读
- ios - iPhone Mini 中的导航栏间隙问题
- javascript - 在 Chrome 中关闭浏览器时如何检测事件?
- angular - 访问 observable 之外的数据
- tensorflow - 为什么当输入形状清晰且固定时,model.summary() 会给出形状 None?
- javascript - 编辑fabric.Textbox时如何获取当前光标位置
- html - 将左浮动视频放在段落底部
- reactjs - React/Typescript 属性 'ID' 不存在于类型'never'.ts(2339)
- mysql - TypeORM MariaDB 主键为 UUID
- reactjs - 在我的 React 项目中,Getting 没有提供名为“default”的导出
- python-3.x - 错误:sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) 没有这样的表: