Yesterday the test to see a bug, as follows:
"3.1.0" When the survey is composed of Chinese and numerals, the first Chinese text will be automatically wrapped.
The final solution is to add this method:
PrivateString Autosplittext (FinalTextView TV) { FinalString Rawtext = Tv.gettext (). toString ();//Original Text FinalPaint TVPaint = Tv.getpaint ();//paint, containing information such as fonts Final floatTvwidth = Tv.getwidth ()-Tv.getpaddingleft ()-tv.getpaddingright ();//Control Available Width//split the original text by rowsstring[] Rawtextlines = Rawtext.replaceall ("\ R", ""). Split ("\ n")); StringBuilder Sbnewtext=NewStringBuilder (); for(String rawtextline:rawtextlines) {if(Tvpaint.measuretext (Rawtextline) <=tvwidth) { //if the entire row width is within the available width of the control, it is not processedsbnewtext.append (Rawtextline); } Else { //if the entire row width exceeds the available width of the control, it is measured by character and wraps manually at the previous character beyond the available width floatLineWidth = 0; for(intCNT = 0; CNT! = Rawtextline.length (); ++CNT) { CharCH =Rawtextline.charat (CNT); LineWidth+=tvpaint.measuretext (string.valueof (ch)); if(LineWidth <=tvwidth) {sbnewtext.append (CH); } Else{sbnewtext.append ("\ n"); LineWidth= 0; --CNT; }}} sbnewtext.append ("\ n"); } //get rid of the excess at the end. if(!rawtext.endswith ("\ n") {Sbnewtext.deletecharat (Sbnewtext.length () )-1); } returnsbnewtext.tostring (); }
View Code
After loading the call:
Tvdes.settext (Desc.getsurvey_conclusion ()); Tvdes.settext (Autosplittext (tvdes));
View Code
If there is an unhealthy problem, call it in a different way:
Viewtreeobserver observer = tvdes.getviewtreeobserver (); Observer.addongloballayoutlistener ( new Viewtreeobserver.ongloballayoutlistener () { @ Override publicvoid ongloballayout () { tvdes.settext (Autosplittext (tvdes)); } });
View Code
You can do it.
TextView loaded hybrid character wrapping solution in Android