对话框片段文本视图宽度



我正在尝试实现dialogFragments。它们显示和关闭都很好,但问题是对话框和文本视图的宽度。当我希望跨越多个文本视图时,文本视图将只在一行。他们还实现了滚动,所以我能看到所有内容的唯一方法就是用手指滚动。

这是XML

<TextView
    android:id="@+id/website_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_margin="10dip"
    android:text="@string/website_text"
    android:textColor="@android:color/white" />
<TextView
    android:id="@+id/email_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/website_text"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_margin="10dip"
    android:text="@string/email_text"
    android:textColor="@android:color/white" />
<TextView
    android:id="@+id/information_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/email_text"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_margin="10dip"
    android:text="@string/information_text"
    android:textColor="@android:color/white" />
<TextView
    android:id="@+id/copyright_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/information_text"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_margin="10dip"
    android:text="@string/copyright_text"
    android:textColor="@android:color/white" />
<TextView
    android:id="@+id/apparentmedia_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/copyright_text"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center_horizontal"
    android:layout_margin="10dip"
    android:text="@string/apparentmedia_text"
    android:textColor="@android:color/white" />

这是DialogFragment

公共类InformationDialog扩展DialogFragment{

int mNum;
/**
 * Create a new instance of MyDialogFragment, providing "num"
 * as an argument.
 */
public static InformationDialog newInstance(int num) {
    InformationDialog d = new InformationDialog();
    // Supply num input as an argument.
    Bundle args = new Bundle();
    args.putInt("num", num);
    d.setArguments(args);
    return d;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNum = getArguments().getInt("num");
    // Pick a style based on the num.
    int style = DialogFragment.STYLE_NORMAL, theme = 0;
    switch ((mNum-1)%6) {
        case 1: style = DialogFragment.STYLE_NO_TITLE; break;
        case 2: style = DialogFragment.STYLE_NO_FRAME; break;
        case 3: style = DialogFragment.STYLE_NO_INPUT; break;
        case 4: style = DialogFragment.STYLE_NORMAL; break;
        case 5: style = DialogFragment.STYLE_NO_TITLE; break;
        case 6: style = DialogFragment.STYLE_NO_FRAME; break;
        case 7: style = DialogFragment.STYLE_NORMAL; break;
    }
    switch ((mNum-1)%6) {
        case 2: theme = android.R.style.Theme_Panel; break;
        case 4: theme = android.R.style.Theme; break;
        case 5: theme = android.R.style.Theme_Light; break;
        case 6: theme = android.R.style.Theme_Light_Panel; break;
        case 7: theme = android.R.style.Theme_Light; break;
    }
    setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Light_Panel);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    TextView websiteText, emailText;;
    View v = inflater.inflate(R.layout.info, container, false);
    v.setLayoutParams(new LinearLayout.LayoutParams(50, LayoutParams.WRAP_CONTENT, 1));
    websiteText =  (TextView) v.findViewById(R.id.website_text);
    websiteText.setText(R.string.website_text);
    websiteText.setWidth(300);

    emailText =(TextView) v.findViewById(R.id.email_text);
    emailText.setText(R.string.email_text);
    Linkify.addLinks(emailText, Linkify.EMAIL_ADDRESSES);
    Linkify.addLinks(websiteText, Linkify.WEB_URLS);
    return v;
}

}

以及我如何称之为

    DialogFragment newFragment = MyDialog.newInstance();
       newFragment.show(getFragmentManager(), "dialog");

我从来没有得到过答案,但我认为很多人对此有问题,因为安卓团队在博客中对此进行了讨论

最新更新