Итак, я создаю собственный AlertDialog с помощью Builder.У меня есть пользовательское представление, которое я надуваю в диалоге со следующим макетом:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText android:id="@+id/edit_username"
style="@style/EditPassword"
android:hint="@string/login_username_hint" />
<EditText android:id="@+id/edit_password"
style="@style/EditPassword"
android:hint="@string/login_password_hint" />
</LinearLayout>
Стиль android: layout_height для элементов управления EditText установлен на «wrap_content».Когда я показываю диалог с этим пользовательским видом, диалог растягивается, чтобы заполнить высоту всего экрана.Независимо от того, что я установил layout_height на LinearLayout (включая жестко запрограммированные значения пикселей), он все равно заполняет весь экран в моем эмуляторе.
Я надеюсь, что здесь есть что-то простое, чего мне не хватает?
РЕДАКТИРОВАТЬ: Я посмотрел в Средстве просмотра иерархии, и макет, который я включил в этот вопрос, правильно определен, но он заключен в FrameLayout в FrameLayout, а самый внешний FrameLayout установлен в «wrap_content», но выполняет рендеринг вСредство просмотра с кучей пустого пространства под ним.
РЕДАКТИРОВАТЬ 2: По запросу, код, который раздувает макет.
protected Dialog onCreateDialog(int id) {
switch(id) {
case AUTHENTICATION_DIALOG:
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
final View loginView = inflater.inflate(R.layout.login_dialog, null);
return new AlertDialog.Builder(HomeActivity.this)
.setTitle("Upload profile data")
.setView(loginView)
.setPositiveButton("Upload", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText userName = (EditText)loginView.findViewById(R.id.edit_username);
EditText password = (EditText)loginView.findViewById(R.id.edit_password);
String userNameStr = StringUtils.convertToTrimmedString(userName.getText());
String passwordStr = StringUtils.convertToTrimmedString(password.getText());
if (userNameStr.equals("") || passwordStr.equals("")) {
new AlertDialog.Builder(HomeActivity.this)
.setTitle("Required fields missing")
.setMessage("You must enter a username and password")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
HomeActivity.this.showDialog(AUTHENTICATION_DIALOG);
dialog.dismiss();
}
}).show();
} else {
dialog.dismiss();
} // end if user entered username and password
} // end "Upload" onClick
}) // end setPositiveButton DialogInterface.OnClickListener()
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
} // end "Cancel" onClick
}).create();
default:
return null;
}
}