我有这个自定义对话框的布局,这对普通和小型设备都很好,但在大型设备的情况下,它的宽度不适合宽度(填充父级),但我可以手动给它一些dp值,以达到我想要的大小。我想知道为什么不填补父母的工作默认。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#f70000"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textViewInvoice"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"

                    android:textColor="#FFFFFF"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >

                    <Button
                        android:id="@+id/buttonPrint"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/buttonPrint" />

                    <Button
                        android:id="@+id/buttonCancel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/buttonCancel" />

                </LinearLayout>

            </LinearLayout>
        </ScrollView>

    </LinearLayout>

最佳答案

试试这个…

    Dialog dialog = new Dialog(YourActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = dialog.getWindow();
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    RelativeLayout lay = new RelativeLayout(YourActivity.this);
    View dialogView = inflater.inflate(R.layout.your_dialog_layout,
            lay);
    dialog.setContentView(dialogView);
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

10-04 19:47