我有个亲戚布局R和一个alertdialog答:我想设置相同,R A的位置和尺寸这样的位置和尺寸上:下面的一组代码的Android alertdialog设置布局
A.position_x = R.get_position_x()
A.position_y = R.get_position_y()
A.width = R.get_width()
A.height = R.get_height()
我有个亲戚布局R和一个alertdialog答:我想设置相同,R A的位置和尺寸这样的位置和尺寸上:下面的一组代码的Android alertdialog设置布局
A.position_x = R.get_position_x()
A.position_y = R.get_position_y()
A.width = R.get_width()
A.height = R.get_height()
使用AlertDialog
在屏幕的上方:
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle("Title:");
builder.setMessage("Are you sure to Exit?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Set ypu positive code on OK button
finish();
}
});
// Setting Negative "NO" Btn
builder.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Dialog
AlertDialog dialog = builder.create();
dialog.getWindow().setGravity(Gravity.TOP);
dialog.show();
它不工作BEC我希望将对话框设置为相对布局,并将其宽度和高度设置为相对布局。 –
好的,你可以在你的问题中发布你的对话框代码和相对布局的xml代码。 –
Get height,width and position x and y of relativelayout from below code
rel1 = (RelativeLayout)findViewById(R.id.rel1);
rel1.post(new Runnable()
{
@Override
public void run()
{
widthRel1 = rel1.getWidth();
heightRel1 = rel1.getHeight();
xRel1 = (int) rel1.getX();
yRel1 = (int) rel1.getY();
}
});
Then apply it to Dialog
final Dialog alertDialog = new Dialog(MainActivity.this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.template_menu);
Window window = alertDialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.x = xRel1; //x position
wlp.y = yRel1; //y position
wlp.height = heightRel1;
wlp.width = widthRel1;
wlp.gravity = Gravity.TOP | Gravity. LEFT;
window.setAttributes(wlp);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
alertDialog.show();
代替position_x离开position_y使用和顶部 – arun
你有GET PARAM并设置PARAM使用该 –