Khe*_*raj 3 android android-layout bottom-sheet
BottomSheetDialogFragment当我打开它时,我打开一半(意思是不完全).
fragment.show(supportFragmentManager, "my_frag")
Run Code Online (Sandbox Code Playgroud)
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
...
/>
Run Code Online (Sandbox Code Playgroud)
ADM*_*ADM 22
通过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;
}
Run Code Online (Sandbox Code Playgroud)
只需保持布局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;
}
Run Code Online (Sandbox Code Playgroud)
import com.google.android.material在这种情况下,请确保所有导入.
| 归档时间: |
|
| 查看次数: |
4780 次 |
| 最近记录: |