2017-08-03 208 views
2

我有一個文本視圖,其中包含一段信息。我想讓文字不是通過字符來包裝。目前,如果這個詞很長,它會在詞的中間插入一個連字符並打破。在android中用文字換行TextView

這是我TextView的XML代碼

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:layout_above="@+id/title" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginBottom="13dp" 
    android:id="@+id/scrollView2"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/content" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="130dp" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:ellipsize="start" 
      android:text="TextView" 
      android:textColor="#000000" 
      android:textSize="16sp" 
      android:visibility="visible" /> 
    </LinearLayout> 
</ScrollView> 

感謝您的幫助。

+0

您的代碼Android Studio中正常工作。你使用的是什麼android版本? – Darush

+0

這可能有所幫助:https://stackoverflow.com/questions/4851659/how-to-wrap-text-in-textview-in-android – Darush

回答

1

這是Android 6 Marshmellow中的一件新事物。

嘗試添加以下內容到TextView的

android:hyphenationFrequency="none"

+0

完美的工作,謝謝! – Bernard

-1

您需要用/ n來分段。你也可以使用非破壞空間來控制斷線。

+1

我想避免硬編碼的突破,以便它看起來不錯屏幕尺寸。 – Bernard

+0

這是我讀過的最糟糕的解決方案 – Logi24

相關問題