我创建了这个课程:
public class AlertDialogFragment extends DialogFragment {
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_alert, container);
...
我的dialog_alert.xml布局文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/dialog_background">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:paddingLeft="@dimen/keyline_4"
android:paddingRight="@dimen/keyline_4"
android:paddingTop="@dimen/keyline_4">
<TextView
android:id="@+id/title"
style="@style/DialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:text="@string/visible_by"
android:visibility="gone"/>
<TextView
android:id="@+id/content"
style="@style/DialogContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vos données de connexion sont incorrectes." />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="@dimen/keyline_4"
android:paddingRight="@dimen/keyline_1"
android:paddingBottom="@dimen/keyline_1"
android:layout_gravity="right">
<TextView
android:id="@+id/negative_button"
style="@style/DialogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/keyline_0"
android:text="negative"
android:visibility="gone" />
<TextView
android:id="@+id/positive_button"
style="@style/DialogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="positive" />
</LinearLayout>
</LinearLayout>
结果是:
我已定义&#34; match_parent&#34;填充等于24dp的属性(= @ dimen / keyline_4)。
感谢您的帮助!