5

最終編集:まあ、完全なハックですが、現時点では「まあ」のように機能します。この問題を修正するために私がしたことはandroid:lines="10"、TextView に追加することだけで、2.2 や ICS/JB のようなすべてが表示されました。まったく抽象的ではないため、完全なハックですが、何でも:P..助けてくれたみんなに感謝します!

Gingerbread (API 10) を使用してカスタム ダイアログにテキストを表示できません。ここに示すように、表示される唯一のテキストは最初の行です。Froyo、ICS、および JB では、すべてのテキスト行が表示されます。XML のことだと思いますが、よくわかりません。どこが間違っていますか?

編集:私が試したこと:

-RelativeLayout を LinearLayout に変更する

-ScrollViewに追加

- 文字列を 1 行にまとめる

- requestLayout() と forceLayout() の使用

-ダイアログ関数を別のクラスに入れる

-ボタンの余白を取り除く

- HTML の代わりに \n を使用

-AlertDialog

-TextView の inputType および singleLine XML 属性

-あと1つか2つ忘れていると思います..

XML は次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:id="@+id/layout_root"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/dia_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="17dp"
        android:padding="5dp"/>

    <View 
        android:id="@+id/bar"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#CCCCD0"
        android:layout_below="@+id/dia_text"/>

    <Button
        android:id="@+id/dialogbuttongotit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/dialog_confirm"
        android:textSize="20dp"
        android:layout_marginTop="0dp"
        android:layout_marginRight="0dp"
        android:layout_below="@+id/bar"/> 
</RelativeLayout>

コードは次のとおりです。

final Context context = this;
public void addListenerOnRectHelpButton() {

    img = (ImageButton) findViewById(R.id.rect_img); 
    img.setOnClickListener(new View.OnClickListener() { 
        public void onClick(View v) {

               //create a new dialog
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom_dialogs);
            dialog.setTitle("Rectangular Area");

            // set the custom dialog text
            TextView text = (TextView) dialog.findViewById(R.id.dia_text);
            String dialog_rect_txt = "<u>Area of a Rectangular Channel</u><br />" +
                    "Height x Width (H x W)<br />--Example:<br />" +
                    "Height: 3ft,  Width 5ft<br />" +
                    "H x W = 3ft x 5ft = 15ft<sup>2</sup><br />";
            text.setText(Html.fromHtml(dialog_rect_txt));

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogbuttongotit);
            // if button is clicked, close the custom dialog
            dialogButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();             

        }

    });

}
4

2 に答える 2

0

TextView で requestLayout() を呼び出してみましたか?

...
text.setText(Html.fromHtml(dialog_rect_txt));
text.requestLayout();
...
于 2012-07-25T14:30:50.457 に答える
0

独自に構築する代わりに、単に AlertDialog を使用しないのはなぜですか?

Dialog dlg = new AlertDialog.Builder(this).setTitle(
    "Rectangular Area").setMessage(dialogRectText).setPositiveButton(
     "Got It", clickListener).create();
dlg.show();
于 2012-07-25T16:42:00.797 に答える