我试图为我的对话设置位置。我使用自定义视图,因此我使用Dialog
类创建警报对话框。我的问题是,x,y位置不适用于Dialog
警报但适用于AlertDialog
警报。我不知道为什么会这样。提前感谢...
使用Dialog
类的警报对话框代码,此对话框未显示给定位置
Dialog dialog = new Dialog(getActivity(),
android.R.style.Theme_Translucent_NoTitleBar);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
Log.v("ShelfShareFragment", "X-Axis: "+mXAxis+" Y-Axis: "+mYAxis);
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
dialog.getWindow().setWindowAnimations(R.anim.anim_fade_in);
wmlp.x = mXAxis; // x position
wmlp.y = mYAxis; // y position
LayoutInflater inflater = (LayoutInflater) getActivity()
.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_shelf_share,
null);
dialog.setContentView(dialogView);
dialog.show()
使用AlertDialog
类的警报对话框代码。这个工作正常,但我需要使用Dialog
类创建我的对话框。
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
LayoutInflater inflater = (LayoutInflater) getActivity()
.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.dialog_shelf_share,
null);
builder.setTitle("Checking");
builder.setView(dialogView);
builder.setCancelable(true);
AlertDialog dialog = builder.create();
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
Log.v("ShelfShareFragment", "X-Axis: "+mXAxis+" Y-Axis: "+mYAxis);
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = mXAxis; // x position
wmlp.y = mYAxis; // y position
dialog.getWindow().setWindowAnimations(R.anim.anim_zoom_out);
dialog.show();
答案 0 :(得分:0)
我认为你错过了代码
getWindow().setAttributes()
请检查