Android没有调整足够大的自定义对话框
我正在使用一个包含文本字段、图像和按钮的自定义对话框。文本可以包含HTML。有时,当文本足够长时,对话框的底部会被切掉。我怎样才能防止这种情况?我想让Android来决定对话框的大小,但它似乎没有这样做。在这种情况下,我需要自己调整对话框的大小吗 这是布局图Android没有调整足够大的自定义对话框,android,dialog,Android,Dialog,我正在使用一个包含文本字段、图像和按钮的自定义对话框。文本可以包含HTML。有时,当文本足够长时,对话框的底部会被切掉。我怎样才能防止这种情况?我想让Android来决定对话框的大小,但它似乎没有这样做。在这种情况下,我需要自己调整对话框的大小吗 这是布局图 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/alert_root_incorrect"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/alert_root_incorrect"
style="@style/AlertDialogTheme"
android:background="@drawable/rounded_alert"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/rounded_alert"
>
<TableLayout
android:stretchColumns="0"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:textStyle="bold"
android:text="Sorry, that's wrong!"
android:textColor="@color/gray_dark" />
<ImageView
android:id="@+id/check"
android:background="@drawable/xmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/alert_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:text="In fact, this is where the explanation will go. Something about how this passage related to the topic"
android:textColor="#000000" />
<Button
android:id="@+id/okay_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:background="@drawable/rounded_alert_button"
android:text="Okay"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
下面是我的一个简短意思
谢谢
John这并不完美,但我通过设置对话框相对于默认显示的布局来纠正它
dialog = new Dialog(this, R.style.AlertDialogTheme);
dialog.setContentView(layout);
Window window = dialog.getWindow();
window.setLayout(
(int)(window.getWindowManager().getDefaultDisplay().getWidth() * .90),
(int)(window.getWindowManager().getDefaultDisplay().getHeight() * .90 ));
dialog.setCancelable(false);
只要调整“.90”值,直到感觉正确为止。以下是解决方案:
可能是您选择的
样式
中有一些大小限制,这会阻止您调整对话框的大小。试着不穿款式,看看是否有区别。带有layout\u weight
的LinearLayout
比TableLayout
容易,为什么有两个嵌套的LinearLayout
您只需要一个。尽可能消除像这样的“额外”视图,它们可能会干扰布局。在设置textSize
时,我也无法调整按钮的大小。您可以尝试从按钮中删除填充。如果您的背景是9-patch,那么边距设置也可能存在问题。
dialog = new Dialog(this, R.style.AlertDialogTheme);
dialog.setContentView(layout);
Window window = dialog.getWindow();
window.setLayout(
(int)(window.getWindowManager().getDefaultDisplay().getWidth() * .90),
(int)(window.getWindowManager().getDefaultDisplay().getHeight() * .90 ));
dialog.setCancelable(false);