我不明白爲什麼我的對話框佈局行爲很奇怪。如果我使用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