我不明白为什么我的对话框布局行为很奇怪。如果我使用android:layout="wrap_content"
作为最后一个小部件,它会使对话非常窄。Android自定义对话框布局不起作用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam bibendum leo eget eros mattis nec eleifend nulla elementum. Suspendisse suscipit suscipit enim in mollis. "
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Don't remind me later"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
/>
</LinearLayout>
Java代码。
private void showDialog() {
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dial);
dialog.setTitle("Dialog title");
dialog.show();
}
看到我的答案在这个链接http://stackoverflow.com/questions/8894300/fully-custom-dialog-in-android-with-the-same-look-regardless-device/8894444#8894444.and upvote if你喜欢 – Sameer 2012-02-20 07:02:03
有同样的问题,但我不得不使用fill_parent,因为它是1.6。奇怪的确如此,但可能与窗口的窗口布局计算有关... – codeScriber 2012-02-20 07:04:12