我需要帮助以进一步了解自定义对话框。
我创建自定义对话框,但为什么大小不成比例,像这样..
这就是我用自定义布局调用对话框的方式。
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_dp3_out); //layout for dialog
dialog.setTitle("Add a new friend");
dialog.show();
这是自定义布局......
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_time_load"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtTimeLoad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Jam Muat Dari"
android:inputType="time"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_time_finish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtTimeFinish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Jam Muat Sampai"
android:inputType="time"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_from"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtFrom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Asal"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Tujuan"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_vehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nomor Kendaraan"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_vehicle_driver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtVehicleDriver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Supir"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_vehicle_codriver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/txtVehicleCodriver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Kenek"
android:maxLines="1"
android:textColor="#000000" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
请让我知道我哪里错了..但是..
答案 0 :(得分:4)
您应该使用 setLayout 方法
PATH: ....; C:\Anaconda3\Lib\site-packages\PyQt5; ...
<强>动态强>
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_dp3_out);
dialog.getWindow().setLayout( , ); // Add Width and Height
dialog.show();