DialogFragment TextView宽度

时间:2012-01-26 19:47:31

标签: android android-fragments

我试图实现dialogFragments。它们显示和解除罚款,但问题是对话框的宽度以及textviews。当我希望跨越多个时,文本视图将只在一行上。他们还实现滚动,所以我能看到所有内容的唯一方法就是用手指滚动。

这是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");

1 个答案:

答案 0 :(得分:1)

我从来没有得到过这方面的答案,但我会假设很多人都有问题,因为安卓团队blogged about it