Search code examples
androidtextviewword-wrap

Wrap text by word in android TextView


I have a text view that contains a paragraph of information. I would like to make the text wrap by word not by character. Currently if the word is to long it will insert a hyphen and break in the middle of the word.

This is my xml code for the TextView

    <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>

Thanks for any help.


Solution

  • This is a new thing in android 6 Marshmellow.

    Try adding this to your TextView

    android:hyphenationFrequency="none"