我有一个对话框optionsDialog
,我想把它推到窗口边框的顶部,所以我正在尝试这个:
WindowManager.LayoutParams params = optionsDialog.getWindow().getAttributes();
params.gravity = Gravity.TOP;
params.y = -1000;
optionsDialog.getWindow().setAttributes(params);
但它不起作用。请帮忙!
答案 0 :(得分:0)
如果你的对话框有一个RelativeLAyout作为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);