【问题标题】:Text cuts off in Dialog对话框中的文本被截断
【发布时间】:2012-07-23 07:10:13
【问题描述】:

最终编辑:好吧,完全破解,但目前我喜欢“meh”它有效。我为解决这个问题所做的只是将android:lines="10" 添加到 TextView 中,它显示了 2.2 和 ICS/JB 中的所有内容。完全破解,因为它根本不是抽象的,而是任何东西:P..感谢所有提供帮助的人!

我在使用 Gingerbread (API 10) 的自定义对话框中显示文本时遇到问题。唯一显示的文本是第一行 shown here。在 Froyo、ICS 和 JB 中,它显示 with every line of text shown。我相信这是一个 XML 的东西,但我不确定。我哪里错了?

编辑:我尝试过的:

-将RelativeLayout改为LinearLayout

-在ScrollView中添加

-把我的字符串放在一行

-使用 requestLayout() 和 forceLayout()

-将对话框函数放在一个单独的类中

-取出按钮中的边距

-使用 \n 而不是 HTML

-警报对话框

-inputType 和我的 TextView 上的 singleLine XML 属性

-我想还有一两个我忘记了..

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

        }

    });

}

【问题讨论】:

  • 我建议改用支持库和对话框片段。
  • 或者您可以简单地将您的文本放入 scrollView...
  • @yahya 我试过把它放在一个滚动视图中,但这并没有解决问题:/
  • 你试过singleLine或inputType XML属性吗?
  • ...最后,设置“lines”参数才是真正解决问题的方法,所以你是对的。

标签: android android-layout android-xml


【解决方案1】:

您是否尝试过在 TextView 上调用 requestLayout()?

...
text.setText(Html.fromHtml(dialog_rect_txt));
text.requestLayout();
...

【讨论】:

  • 它没有帮助
【解决方案2】:

为什么不直接使用 AlertDialog 而不是自己构建?

Dialog dlg = new AlertDialog.Builder(this).setTitle(
    "Rectangular Area").setMessage(dialogRectText).setPositiveButton(
     "Got It", clickListener).create();
dlg.show();

【讨论】:

  • 我尝试了一个 AlertDialog,并遇到了同样的问题。我也刚刚尝试(使用 AlertDialog)将字符串放入 NO 新行和 ended up with this。这意味着在 2.3 上它不会尊重我的自定义对话框或 AlertDialog 的 layout_width/height?很奇怪……
猜你喜欢
  • 2014-02-23
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多