简体   繁体   中英

How to word wrap in textview so it doesn't break words up occaisionally

I have this code below that deals with the text view for my questions:

    <TextView
        android:id="@+id/textquestion"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_margin="5dp"
        android:gravity="center"
        android:text="Your Question Display Hear....Your Question Display Hear....Your Question Display Hear....Your Question Display Hear...."
        android:textColor="@color/white"
        android:textSize="20sp"
        android:textStyle="bold"
        android:scrollHorizontally="false"/>

I have however noticed something. Sometimes if the word reaches the end and it doesn't fit, instead of moving the word down to the next line, it breaks the word up with a - like so.

This is an example test to show that th-
is text breaks as you can see and not
move the word down to the next line.

What do I need to include in the xml above in order to be able to word wrap it?

试试看

android:breakStrategy="simple"

You can do it by using breakStrategy inside your xml or dynamically setting property

Total three type of breakStrategy available
1)simple,
2)high_quality,
3)balanced

You can use any of from above which give you different line break strategy,

android:breakStrategy="high_quality"

Also, find one image on google which explain you with graphics https://t1.daumcdn.net/cfile/tistory/267FFD3E57BADA6121

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM