Java Android自定义AlertDialog高度不符合布局参数
因此,我正在使用生成器创建一个自定义AlertDialog。我有一个自定义视图,在对话框中使用以下布局进行膨胀:Java Android自定义AlertDialog高度不符合布局参数,java,android,android-layout,Java,Android,Android Layout,因此,我正在使用生成器创建一个自定义AlertDialog。我有一个自定义视图,在对话框中使用以下布局进行膨胀: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:
<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>
所以我改用了一个相对论,比如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_below="@+id/edit_username"
android:hint="@string/login_password_hint" />
</RelativeLayout>
而且效果很好。我切换回Linear进行测试,当我切换回LinearLayout时,它显示出旧的破坏行为。我将不标记这个答案,希望有人能告诉我为什么在线性布局与相对布局之间会出现异常。不知道,没有足够的细节,抱歉。你为什么不为此创建一个新对话框;然后设置内容视图?我更乐意让AlertDialog类处理繁重的工作,而只是担心从DialogInterface中的两个EditText字段中获取文本。OnClickListener能否将代码发布到添加AlertDialog的位置?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_below="@+id/edit_username"
android:hint="@string/login_password_hint" />
</RelativeLayout>