Requirements: Enables long text scrolling to stop, so long strings need to be truncated to a string array of the specified TextView length, and then implemented using Viewfilpper.
The
split code is as follows:
/* * Split string on request/public static string[] Getlinestrs (string content, Paint Paint, float width, float textsize)
{paint.settextsize (TEXTSIZE);//note1: the measuring tool first needs to define the unit int index = 0;
int start = 0;
int end = 0;
float textlength = paint.measuretext (content); int linenum = (int) math.ceil (1.5*textlength/width);//note2: Calculate line number because of inaccurate judgment, increase the margin 1.5 times times, and finally deal with string[] Msplittextparts
= new String[linenum];
for (int i = 0; I <= content.length (); i++) {end = i; float measurelength = paint.measuretext (content, start, end);//note3:[start,end) range of String if (Measurelength >=
width) {Msplittextparts[index] = string for range of content.substring (start, end);//note4:[start,end)
start = end;
index++;
} if (end = = Content.length ()) {Msplittextparts[index] = content.substring (start, end); Return arrays.copyof (Msplittextparts,index);//note5: Because the number of rows is inaccurate, you need to clear the unassigned Null value string}} return null;
The reason for the
Guessing partition is: mixed in Chinese and English. It may be a half angle problem of the whole horn.
After the test found:
1, in all English state, half the total angle calculation of the standard line number (not after 1.5 times times the allowance correction) are OK.
2, in all Chinese state, the standard line number (not 1.5 times times the allowance correction) of the half angle calculation is OK.
3, the standard number of rows calculated is larger than the actual number of rows captured in the mixed state of Chinese and English. There is doubt here.