Android's handling of strings

Source: Internet
Author: User
Tags mixed range split

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.