标签云

微信群

扫码加入我们

WeChat QR Code

So I've seen many posts on SO and other places about android not wrapping text in certain circumstances, but have come across what looks like a really bad oversight that I don't know exactly how to fix.When entering text into a multi-line EditText, word/character wrap behaves normally until you reach the edge of the bounds of the edit text and just enter in a bunch of spaces instead of wrapping the text. Really, it would just be "wrapping" the spaces, which would make sense to not actually wrap the text...that is, as long as you aren't centering the text, at which point those extra spaces just push your text off the left edge.If you enter another character after the spaces, the EditText suddenly word wraps and remove all the spaces.Go ahead and try it out- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"><EditText android:background="#99FF0000"android:id="@+id/message_edit_text"android:textSize="30sp"android:gravity="center"android:textAlignment="center"android:layout_width="100dp"android:scrollHorizontally="false"android:layout_height="100dp"android:singleLine="false"android:maxWidth="300dp"android:isScrollContainer="false"android:layout_weight="1"android:inputType="text|textCapSentences|textMultiLine|textNoSuggestions"/></RelativeLayout>All you need to do to test is to enter is a little as a single character, and then just enter in spaces and you'll see if fly off the left edge.Any ideas how to stop this horrible behavior and retain text size?Extra credit: Don't just add a newline to the string.


stackoverflow.com/questions/10610842/…

2019年04月22日46分23秒

eee All that does is intercept newlines.The problem is that it isn't creating newlines with a long tail of spaces.

2019年04月22日46分23秒