DialogFragment TextView Width - PullRequest
       0

DialogFragment TextView Width

0 голосов
/ 26 января 2012

Я пытался реализовать 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");

1 Ответ

1 голос
/ 16 мая 2012

Я так и не получил ответ на этот вопрос, но я бы предположил, что у многих людей возникла проблема с ним, так как команда Android написала в блоге об этом

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...