如何将 android 对话框推得比顶部 window 边框更远?
how to push android dialog further than top window border?
我有一个对话框 optionsDialog
,我想将它推到 window 边框的顶部,所以我正在尝试这样做:
WindowManager.LayoutParams params = optionsDialog.getWindow().getAttributes();
params.gravity = Gravity.TOP;
params.y = -1000;
optionsDialog.getWindow().setAttributes(params);
但它不起作用。请帮忙!
如果你的对话框有一个 RelativeLAyout 作为 root 你可以使用这个(如果不调整它到你作为 root 的视图):
RelativeLayout dialogWrapper = (RelativeLayout) optionsDialog.findViewById(R.id.your_dialog_root_view_id); //NOtice here goes id for root RelativeLayout or anyother root view
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, -1000, 0, 1000); //MArgins: left top right bottom
dialogWrapper.setLayoutParams(params);
我有一个对话框 optionsDialog
,我想将它推到 window 边框的顶部,所以我正在尝试这样做:
WindowManager.LayoutParams params = optionsDialog.getWindow().getAttributes();
params.gravity = Gravity.TOP;
params.y = -1000;
optionsDialog.getWindow().setAttributes(params);
但它不起作用。请帮忙!
如果你的对话框有一个 RelativeLAyout 作为 root 你可以使用这个(如果不调整它到你作为 root 的视图):
RelativeLayout dialogWrapper = (RelativeLayout) optionsDialog.findViewById(R.id.your_dialog_root_view_id); //NOtice here goes id for root RelativeLayout or anyother root view
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, -1000, 0, 1000); //MArgins: left top right bottom
dialogWrapper.setLayoutParams(params);