自定义视图使用onCreateView在DialogFragment [英] Custom View using onCreateView in a DialogFragment

查看:131
本文介绍了自定义视图使用onCreateView在DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直试图弄清楚这一点现在一段时间:

Been trying to figure this out for a while now:

我试图创建一个使用在所示的标准方法的自定义对话框开发网站

I'm trying to create a custom dialog using the standard approach shown on the Dev site.

public class CustomDialog extends DialogFragment {    
    private OnDialogResultListener mOnDialogResultListener = null;
    public void setOnDialogResultListener(OnDialogResultListener dialogResultListener) {
        mOnDialogResultListener = dialogResultListener;
    }

    public static CustomDialog newInstance(OnDialogResultListener dialogResultListener) {
        CustomDialog frag = new CustomDialog();        
        frag.setOnDialogResultListener(dialogResultListener);
        return frag;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().setTitle(getString(R.string.Dialog_CustomDialog_Title));
        View v = inflater.inflate(R.layout.customdialog, container, false);
        return v;
    }
}

随着XML之中:

With the XML being:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_height="fill_parent" android:background="@color/white" android:layout_margin="0px" android:layout_width="fill_parent">
    <EditText android:hint="@string/Dialog.CustomDialog.OldPassword" android:layout_marginBottom="@dimen/normalMargin" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/EditText02" android:layout_width="fill_parent"></EditText>
    <EditText android:hint="@string/Dialog.CustomDialog.NewPassword" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/EditText01" android:layout_width="fill_parent"></EditText>
    <EditText android:hint="@string/Dialog.CustomDialog.RetypePassword" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/editText1" android:layout_width="fill_parent">
        <requestFocus></requestFocus>
    </EditText>
    <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="fill_parent">
        <Button android:layout_height="wrap_content" android:text="@string/save" android:layout_width="@dimen/normalButtonWidth" android:id="@+id/btn_Custom_save"></Button>
        <Button android:layout_height="wrap_content" android:text="@string/cancel" android:layout_width="@dimen/normalButtonWidth" android:id="@+id/btn_Custom_cancel"></Button>
    </LinearLayout>
</LinearLayout>

和创建和显示对话框后,我留下了:

And after creating and showing the dialog, I'm left with:

白色背景已应用于强调意外和不希望的行为。

The white background has been applied to emphasize the unexpected and unwanted behavior.

任何想法?我试着改变宽度/高度,在一个水平的LinearLayout使用权重编程设置宽度/高度 - 都无济于事

Any ideas? I've tried changing width/heights, using weights in a horizontal LinearLayout, setting width/height programatically - all to no avail.

推荐答案

我没有拿出一个便宜的修复,我宁可不要使用。

I did come up with a cheap fix, which I would rather not have to use.

在布局中添加0像素高度,2000DP(一些巨大的数字)宽度视图随时随地使其填充对话框框架。

Adding a 0px height, 2000dp (some huge number) width view anywhere in the layout causes it to fill the dialog frame.

这篇关于自定义视图使用onCreateView在DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆