如果文本需要在android上换行,则对话框中不会显示正确的文本>;4
我有一个自定义对话框,在其中我在标题栏中显示一些文本。在android 4.0中,它是截断文本。只有将出现在下一行中。我将下面的xml扩展到对话框中。它在3.2上运行良好 我试过layout_weight=“1”和android:ellipsize=“none”,但没有任何效果如果文本需要在android上换行,则对话框中不会显示正确的文本>;4,android,android-layout,Android,Android Layout,我有一个自定义对话框,在其中我在标题栏中显示一些文本。在android 4.0中,它是截断文本。只有将出现在下一行中。我将下面的xml扩展到对话框中。它在3.2上运行良好 我试过layout_weight=“1”和android:ellipsize=“none”,但没有任何效果 <LinearLayout android:layout_height="fill_parent" android:weightSum="1" android:orientation="ve
<LinearLayout
android:layout_height="fill_parent"
android:weightSum="1"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:background="@drawable/rounded_textbox_base"
android1:layout_width="fill_parent"
android1:minWidth="500dp">
<TableRow
android:id="@+id/tableRow1"
android1:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_button"
android1:gravity="center"
android:layout_weight="1">
<TextView
android:id="@+id/tv_nmp_needmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android1:layout_marginLeft="20dp"
android1:layout_marginRight="20dp"
android:ellipsize="none"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android1:gravity="center"
android1:textColor="@color/white" >
</TextView>
</TableRow>
<LinearLayout
android:id="@+id/linearLayout1"
android:weightSum="1"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android1:layout_gravity="center"
android1:gravity="center"
android1:layout_width="wrap_content"
android1:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:id="@+id/btn_nmp_yes"
android:background="@drawable/dialog_ok_button"
android:layout_width="wrap_content">
</Button>
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/textView1"
android:text="OK"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android1:textColor="#000000">
</TextView>
</LinearLayout>
</LinearLayout>
谢谢,
曼尼什语您可以使用:
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"/>
要限制行数,请在ui元素之间结束换行,或者可以在高度或宽度上设置固定尺寸。它将在末尾用“…”截断textview,但使用此方法,您无法控制它何时断开该行。它可以截断一个单词
第二种方法是在执行textView.setText(…)之前自己构造字符串。您只需确定所需的最大字符数,然后自己在需要的位置截断字符串,并在需要换行时添加“\n”。您是否尝试在字符串中添加“\n”以强制下一行。我希望自动换行的文本可能重复。将“\n”放在一个特定位置将是硬编码。然而,我尝试了它的文本目的,这也不工作。@Geobits,我已经检查了链接,但它在我的情况下没有帮助。我还尝试用linearLayout替换tableLayout,但没有任何效果。问题只出现在>4.0版本Hi Yume,我再次观察了我的应用程序。文本正在下一行换行,但仅。。。都是看得见的。文本不可见。我尝试了maxLine或\n,但它不起作用。您能用concreate示例编辑您的问题吗?(使用\n我认为您应该使用StringBuilder)很好。要控制换行的方式,可以使用TextView的“选框”属性