Jak ustawić margines dynamicznie w systemie Android?

Obecnie wykonuję aplikację na Androida, która zawiera okno dialogowe dostosowywania alertów. Zawiera przycisk, ale nie mogę ustawić marginesu dla przycisku. kod jest podany poniżej. metoda setmargin nie działa

AlertDialog.Builder myDialog = new AlertDialog.Builder(Login.this);
Button button = new Button(Login.this);

button.setText("Send");
LayoutParams buttonLayoutParams 
    = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

button.setLayoutParams(buttonLayoutParams);

resetPassword=editText.getText().toString();

LinearLayout layout = new LinearLayout(Login.this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(textView);
layout.addView(editText);
layout.addView(button);

myDialog.setView(layout);

questionAnswers(4)

yourAnswerToTheQuestion