Longitudinal character display method and system and electronic equipment
By obtaining the control properties and the string properties to be displayed in the Android system, determining the target string and the maximum number of characters per column, and setting the character coordinates, vertical text display is realized, solving the problem of lack of vertical text display controls in the Android system. Improved user experience.
Patent Information
- Application Number
- CN202411044098.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-11-08
AI Technical Summary
There is a lack of controls that support vertical text display in the Android system, which cannot meet the text display needs that require vertical reading such as ultra-narrow screens and reading ancient books, which affects the user experience.
Provide a vertical text display method. By obtaining the control attributes and the string attributes to be displayed, determine the target string and the maximum number of characters per column, and according to the principle that the characters drawn in each column are full, the Set the corresponding character coordinates for each character in the target string in the order to realize vertical text display in the Android system.
It realizes the vertical display of the text to be displayed in the Android system, enriches the interface display effect, improves the user experience, and meets the display needs of different scenarios.
Smart Images

Figure CN118915934A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Android interface development, and in particular to a method, system and electronic device for displaying text vertically. Background Art
[0002] With the rapid development of mobile Internet, Android system, as the mainstream mobile phone operating system, has received increasing attention for its user interface design. As an important element in the user interface, the display effect of text controls directly affects the user experience. Although horizontal text layout is standard, due to aesthetic appeal, cultural preferences and space limitations, more and more application scenarios need to support vertical text display. For example, when reading texts such as ultra-narrow screens, ancient books, and poems that need to be read vertically, horizontally displayed text controls are not flexible enough and cannot meet the personalized needs of users. However, Android officially does not provide text controls that support vertical display. Most of the Android text controls on the market currently only support horizontal display and cannot meet the needs of vertical display. Summary of the invention
[0003] In view of this, the purpose of the present invention is to provide a method, system and electronic device for vertically displaying text, which can display the text to be displayed vertically to meet the display requirements of different scenarios, thereby enriching the interface display effect and improving the user experience.
[0004] In a first aspect, an embodiment of the present invention provides a method for displaying text vertically, which is applied to an Android system, and the method includes: obtaining control properties corresponding to a text control and properties of a string to be displayed corresponding to the string to be displayed; determining a target string and a maximum number of characters per column based on the control properties and the properties of the string to be displayed; the target string is a string that can be fully displayed by the text control in the string to be displayed; traversing the target string, based on the maximum number of characters per column, and on the principle that the characters drawn in each column are fully arranged, setting corresponding character coordinates for each character in the target string in a top-to-bottom order; and drawing the target string in the text control according to the character coordinates and the properties of the string to be displayed.
[0005] Further, the control attributes include control height and control width; the attributes of the string to be displayed include the number of characters to be displayed, the character height and character width corresponding to a single character; based on the control attributes and the attributes of the string to be displayed, the step of determining the target string and the maximum number of characters in each column includes: based on the control height and the character height, determining the quotient of the control height and the character height as the maximum number of characters in each column; based on the control width and the character width, determining the quotient of the control width and the character width as the maximum number of display columns; based on the maximum number of characters in each column and the maximum number of display columns, determining the product of the maximum number of characters in each column and the maximum number of display columns as the maximum number of characters; judging whether the number of characters to be displayed is less than or equal to the maximum number of characters; if so, determining that the string to be displayed is the target string; if not, cutting the string to be displayed based on the maximum number of characters, and determining that the cut string to be displayed is the target string.
[0006] Further, the target string is traversed, and based on the maximum number of characters in each column and on the principle that the characters drawn in each column are fully arranged, the steps of setting corresponding character coordinates for each character in the target string in order from top to bottom include: S1: setting the horizontal coordinate of the character coordinate corresponding to the first character in the target string to 0, the vertical coordinate to 0, and setting the initial value of the number of characters with coordinates in the current column to 1; S2: obtaining the current character without coordinates in the target string, and determining whether the current character without coordinates is a preset line break character; S3: if the current character without coordinates is a preset line break character, determining that the next character of the current character without coordinates is the first character of the column, and setting the character coordinates for the first character of the column according to the preset first coordinate setting rule. Set the corresponding character coordinates, and reset the number of characters with coordinates in the current column to the initial value; S4: if the current character without coordinates is not the preset line break character, determine that the current character without coordinates is a character in the column, set the corresponding character coordinates for the character in the column according to the preset second coordinate setting rule, and add 1 to the number of characters with coordinates in the current column; determine whether the number of characters with coordinates is equal to the maximum number of characters in each column; if so, determine that the next character of the current character without coordinates is the first character of the column, set the corresponding character coordinates for the first character of the column according to the first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value; S5: repeat steps S2-S4 until each character in the target string is set with a corresponding character coordinate.
[0007] Furthermore, the attributes of the string to be displayed include the character width corresponding to a single character; the first coordinate setting rule is to set the ordinate of the first character of the column to 0, and the abscissa to the sum of the abscissa corresponding to the previous character of the first character of the column and the character width.
[0008] Furthermore, the attributes of the string to be displayed include the character height corresponding to a single character; the second coordinate setting rule is to set the horizontal coordinate of the character in the column to be the same as the horizontal coordinate corresponding to the previous character in the column, and the vertical coordinate is the sum of the vertical coordinate corresponding to the previous character and the character height.
[0009] Furthermore, the properties of the string to be displayed include character color; the step of drawing the target string in the text control according to the character coordinates and the properties of the string to be displayed includes: drawing the target strings one by one in the text control based on the character color and the character coordinates.
[0010] Furthermore, before the step of obtaining the control properties corresponding to the text control, the method also includes: creating a custom initial text control; the initial text control inherits from the Android View class; in the initial text control, adding a setText method to obtain the string to be displayed, adding a requestLayout method to layout the initial text control, adding an onMeasure method to set the control properties of the initial text control, and adding an onDraw method to draw the received string to be displayed; determining that the initial text control after adding the setText method, requestLayout method, onMeasure method and onDraw method is a text control.
[0011] In a second aspect, an embodiment of the present invention provides a text vertical display system, which is applied to an Android system, and the system includes: an attribute acquisition module, which is used to obtain control attributes corresponding to a text control and attributes of a string to be displayed corresponding to the string to be displayed; a target string determination module, which is used to determine a target string and a maximum number of characters per column based on the control attributes and the attributes of the string to be displayed; the target string is a string that can be fully displayed by the text control in the string to be displayed; a character coordinate setting module, which is used to traverse the target string, and based on the maximum number of characters per column, on the principle that the characters drawn in each column are fully arranged, set corresponding character coordinates for each character in the target string in a top-to-bottom order; a drawing module, which is used to draw the target string in the text control according to the character coordinates and the attributes of the string to be displayed.
[0012] In a third aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method described above when executing the computer program.
[0013] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and the program code enables the processor to execute the method as described above.
[0014] The embodiment of the present invention provides a method, system and electronic device for vertical text display, which are applied to an Android system. The method includes: obtaining a control attribute corresponding to a text control and a to-be-displayed string attribute corresponding to a to-be-displayed string; determining a target string and a maximum number of characters per column based on the control attribute and the to-be-displayed string attribute; the target string is a string that can be fully displayed by the text control in the to-be-displayed string; traversing the target string, and setting corresponding character coordinates for each character in the target string in a top-to-bottom order based on the maximum number of characters per column and the principle that the characters drawn in each column are fully arranged; and drawing the target string in the text control according to the character coordinates and the to-be-displayed string attribute. This method can display the to-be-displayed text vertically to meet the display requirements of different scenarios, thereby enriching the interface display effect and improving the user experience.
[0015] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0016] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 A flowchart of vertical text display provided in Embodiment 1 of the present invention;
[0019] Figure 2 A flowchart of a method for customizing a text control provided in Embodiment 1 of the present invention;
[0020] Figure 3 A flow chart of a method for determining a target character string and a maximum number of characters per column provided in the first embodiment of the present invention;
[0021] Figure 4 A flowchart of a method for setting corresponding character coordinates for each character provided in the first embodiment of the present invention;
[0022] Figure 5 A schematic diagram of a text vertical display system provided in Embodiment 2 of the present invention;
[0023] Figure 6 This is a schematic diagram of another text vertical display system provided in the second embodiment of the present invention.
[0024] Icons: 1-property acquisition module; 2-target string determination module; 3-character coordinate setting module; 4-drawing module; 5-text control customization module. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] To facilitate understanding of this embodiment, the embodiment of the present invention is described in detail below.
[0027] Embodiment 1:
[0028] Figure 1 This is a flowchart of vertical text display provided in Embodiment 1 of the present invention.
[0029] Reference Figure 1 , a method for displaying text vertically in an Android system, comprising:
[0030] Step S101, obtaining a control attribute corresponding to a text control and a string attribute to be displayed corresponding to a string to be displayed.
[0031] In one embodiment, referring to Figure 2 Before step S101, the method further includes:
[0032] Step S201, creating a customized initial text control; the initial text control inherits from the Android View class.
[0033] Here, an initial file control is created in the JAVA code. The initial file control extends the View class of Android (Android system). The initial file control is a customized user interface self-check, which is used as a basis for supporting the display of the string to be displayed.
[0034] Step S202, in the initial text control, add a setText method to obtain the string to be displayed, add a requestLayout method to layout the initial text control, add an onMeasure method to set the control properties of the initial text control, and add an onDraw method to draw the received string to be displayed.
[0035] Step S203, determining that the initial text control after adding the setText method, requestLayout method, onMeasure method and onDraw method is a text control.
[0036] Specifically, the text control is initialized, and properties such as the character string to be displayed, the text size (font height and font width), the text color, the font, the control height and the control width are set as needed.
[0037] Use the setText(String content) function in the setText method to add the string to be displayed in the text control, and call the requestLayout() method in the text space to re-measure, layout, and draw the control, so that the text content can be modified dynamically at any time. Use the int widthMeasureSpec() function in the onMeasure method to obtain the width of the current control, and use the int heightMeasureSpec() function in the onMeasure method to obtain the height of the current control. Use the Paint object in the onMeasure method to obtain the character height and width of the string to be displayed. The character height is obtained by the getTextSize() function, and the character width is obtained by the measureText("W") function. Use the formula int maxCount=Math.max(1,height / lineHeight) function to calculate the maximum number of characters maxCount in the column, where int lineHeight=(int)getTextSize(), intheight=MeasureSpec.getSize(heightMeasureSpec).
[0038] In the onDraw method, traverse the target string and draw each character in the target string from top to bottom based on the principle that the characters drawn in each column are full, based on the maximum number of characters in each column.
[0039] Step S102, based on the control attributes and the attributes of the string to be displayed, determine the target string and the maximum number of characters in each column; the target string is a string that can be fully displayed by the text control in the string to be displayed.
[0040] Here, the control attributes include the control height and the control width; the attributes of the character string to be displayed include the number of characters to be displayed, the character color, the font, and the character height and character width corresponding to a single character.
[0041] When the maximum number of characters that can be displayed in the text control is less than the number of characters to be displayed, the character string to be displayed is segmented, and the segmented character string to be displayed is determined to be a target character string that can be completely displayed in the text control.
[0042] Specifically, the string to be displayed is obtained as follows:
[0043] String text=getText().toString();
[0044] Paint paint = getPaint();
[0045] float charHeight=paint.getTextSize();
[0046] float charWidth=paint.measureText("W");
[0047] In one embodiment, referring to Figure 3 , the steps of step S102 include:
[0048] Step S301: Based on the control height and the character height, determine the quotient of the control height and the character height as the maximum number of characters in each column.
[0049] Specifically, get the control height and control width as follows:
[0050] int height = MeasureSpec.getSize(heightMeasureSpec); / / Get the height of the control.
[0051] int width=MeasureSpec.getSize(widthMeasureSpec); / / Get the width of the control.
[0052] Get the character height lineHeight and character width charWidth as follows:
[0053] Paint paint = getPaint();
[0054] int lineHeight = (int) getTextSize(); / / Get the character height.
[0055] float charWidth = paint.measureText("W"); / / Get the character width.
[0056] The maximum number of characters in each column, maxCount, is calculated as follows:
[0057] int maxCount = Math.max(1, height / lineHeight); / / The quotient of the control height and the character height is the maximum number of characters in each column.
[0058] Step S302: Based on the control width and the character width, determine the quotient of the control width and the character width as the maximum number of display columns.
[0059] Specifically, the maximum number of display columns maxColumns is calculated as follows:
[0060] maxColumns = Math.max(1, (int) (width / charWidth)); / / The quotient of the control width and the character width is the maximum number of display columns.
[0061] Step S303: Based on the maximum number of characters in each column and the maximum number of display columns, determine the product of the maximum number of characters in each column and the maximum number of display columns as the maximum number of characters.
[0062] Specifically, the maximum number of characters maxVisibleChars is calculated as follows:
[0063] maxVisibleChars = maxCount*maxColumns; / / The product of the maximum number of characters in each column and the maximum number of display columns is the maximum number of characters.
[0064] Step S304, determining whether the number of characters to be displayed is less than or equal to the maximum number of characters.
[0065] Step S305: if yes, determine that the character string to be displayed is the target character string.
[0066] Step S306: If not, the character string to be displayed is segmented based on the maximum number of characters, and the segmented character string to be displayed is determined as the target character string.
[0067] Specifically, the target string targetString is determined as follows:
[0068] StringtargetString=text.substring(0,Math.min(text.length(),maxVisibleChars));
[0069] Step S103, traversing the target character string, and setting corresponding character coordinates for each character in the target character string in a top-to-bottom order based on the maximum number of characters in each column and the principle that the characters drawn in each column are fully arranged.
[0070] Here, the character coordinates corresponding to each character include a horizontal coordinate and a vertical coordinate.
[0071] In one embodiment, referring to Figure 4 The steps of step S103 include:
[0072] Step S1: Set the horizontal coordinate of the character coordinate corresponding to the first character in the target character string to 0, the vertical coordinate to 0, and set the initial value of the number of characters with coordinates in the current column to 1.
[0073] Here, the display position of the first character in the target string in the text control is set as the origin, and the character coordinates corresponding to the first character are determined to be (0,0).
[0074] Step S2: Obtain the current character without coordinates in the target character string, and determine whether the current character without coordinates is a preset line break character.
[0075] Here, when it is detected that the character to be drawn is a line break character, the line break character is not drawn, and the next character is drawn in a new column. The preset line break character is a universal line break character that is pre-set and can be recognized by the Android system.
[0076] Step S3: If the current character without coordinates is a preset line break character, determine that the next character of the current character without coordinates is the first character of the column, set the corresponding character coordinates for the first character of the column according to the preset first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value.
[0077] Here, the first coordinate setting rule is to set the ordinate of the first character of the column to 0, and the abscissa to the sum of the abscissa corresponding to the previous character of the first character of the column and the character width. The ordinate of the first character of the column is 0.
[0078] Step S4: If the current character without coordinates is not the preset line break character, determine that the current character without coordinates is a character in the column, set the corresponding character coordinates for the character in the column according to the preset second coordinate setting rule, and add 1 to the number of characters with coordinates in the current column; determine whether the number of characters with coordinates is equal to the maximum number of characters in each column; if so, determine that the next character of the current character without coordinates is the first character of the column, set the corresponding character coordinates for the first character of the column according to the first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value.
[0079] Here, in the target character string, all characters that are not the first characters of the column are characters in the column, and the vertical coordinates of the characters in the column are not 0.
[0080] The second coordinate setting rule is to set the horizontal coordinate of the character in the column to be the same as the horizontal coordinate corresponding to the previous character in the column, and the vertical coordinate is the sum of the vertical coordinate corresponding to the previous character and the character height.
[0081] When the current column has reached the maximum number of characters with coordinates, a column wrap operation is performed.
[0082] Step S5: Repeat steps S2-S4 until each character in the target character string is assigned a corresponding character coordinate.
[0083] Step S104, drawing the target character string in the text control according to the character coordinates and the attributes of the character string to be displayed.
[0084] In one embodiment, step S104 includes:
[0085] Draw the target string one by one in the text control based on the character color and character coordinates.
[0086] Here, the characters in the target string are drawn one by one based on the onDraw method, wherein the properties of the string to be displayed may also include a font.
[0087] The embodiment of the present invention provides a method for displaying text vertically, which is applied to an Android system. The method includes: obtaining a control attribute corresponding to a text control and a to-be-displayed string attribute corresponding to a to-be-displayed string; determining a target string and a maximum number of characters per column based on the control attribute and the to-be-displayed string attribute; the target string is a string that can be fully displayed by the text control in the to-be-displayed string; traversing the target string, and setting corresponding character coordinates for each character in the target string in a top-to-bottom order based on the maximum number of characters per column and the principle that the characters drawn in each column are fully arranged; and drawing the target string in the text control according to the character coordinates and the to-be-displayed string attribute. This method can display the to-be-displayed text vertically to meet the display requirements of different scenarios, thereby enriching the interface display effect and improving the user experience.
[0088] Embodiment 2:
[0089] Figure 5 This is a schematic diagram of a text vertical display system provided in Embodiment 2 of the present invention.
[0090] Reference Figure 5 , a text vertical display system applied to Android system, including:
[0091] The attribute acquisition module 1 is used to acquire the control attribute corresponding to the text control and the string attribute to be displayed corresponding to the string to be displayed.
[0092] The target string determination module 2 is used to determine the target string and the maximum number of characters per column based on the control properties and the properties of the string to be displayed; the target string is the string that can be fully displayed by the text control in the string to be displayed.
[0093] The character coordinate setting module 3 is used to traverse the target character string, and set the corresponding character coordinates for each character in the target character string in a top-to-bottom order based on the principle that the characters drawn in each column are fully arranged based on the maximum number of characters in each column.
[0094] The drawing module 4 is used to draw the target character string in the text control according to the character coordinates and the properties of the character string to be displayed.
[0095] In one embodiment, the target character string determination module 2 is further configured to:
[0096] Based on the control height and character height, determine the quotient of the control height and character height as the maximum number of characters per column.
[0097] Based on the control width and the character width, determine the quotient of the control width and the character width as the maximum number of display columns.
[0098] Based on the maximum number of characters per column and the maximum number of display columns, the product of the maximum number of characters per column and the maximum number of display columns is determined as the maximum number of characters.
[0099] Determine whether the number of characters to be displayed is less than or equal to the maximum number of characters.
[0100] If yes, determine that the character string to be displayed is the target character string.
[0101] If not, the character string to be displayed is cut based on the maximum number of characters, and the character string to be displayed after the cutting is determined as the target character string.
[0102] In one embodiment, the character coordinate setting module 3 is further used for:
[0103] S1: Set the horizontal coordinate of the character coordinate corresponding to the first character in the target string to 0, the vertical coordinate to 0, and set the initial value of the number of characters with coordinates in the current column to 1.
[0104] S2: Get the current character without coordinates in the target string, and determine whether the current character without coordinates is a preset line break character.
[0105] S3: If the current character without coordinates is a preset line break character, determine that the next character of the current character without coordinates is the first character of the column, set the corresponding character coordinates for the first character of the column according to the preset first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value.
[0106] S4: If the current character without coordinates is not the preset line break character, determine that the current character without coordinates is a character in the column, set the corresponding character coordinates for the character in the column according to the preset second coordinate setting rule, and add 1 to the number of characters with coordinates in the current column; determine whether the number of characters with coordinates is equal to the maximum number of characters in each column; if so, determine that the next character of the current character without coordinates is the first character of the column, set the corresponding character coordinates for the first character of the column according to the first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value.
[0107] S5: Repeat steps S2-S4 until each character in the target character string is set with a corresponding character coordinate.
[0108] The first coordinate setting rule is to set the ordinate of the first character of the column to 0, and the abscissa to the sum of the abscissa corresponding to the previous character of the first character of the column and the character width.
[0109] The second coordinate setting rule is to set the horizontal coordinate of the character in the column to be the same as the horizontal coordinate corresponding to the previous character in the column, and the vertical coordinate is the sum of the vertical coordinate corresponding to the previous character and the character height.
[0110] In one embodiment, the drawing module 4 is further used for:
[0111] Draw the target string one by one in the text control based on the character color and character coordinates.
[0112] In one implementation, referring to Figure 6 , a text vertical display system applied to an Android system, further comprising: a text control customization module 5, the text control customization module 5 is used to:
[0113] Create a custom initial text control; the initial text control inherits from the Android View class.
[0114] In the initial text control, add the setText method to obtain the string to be displayed, add the requestLayout method to layout the initial text control, add the onMeasure method to set the control properties of the initial text control, and add the onDraw method to draw the received string to be displayed.
[0115] Make sure that the initial text control after adding the setText method, requestLayout method, onMeasure method, and onDraw method is a text control.
[0116] The embodiment of the present invention provides a text vertical display system, which is applied to the Android system and can display the text to be displayed vertically to meet the display requirements of different scenes, thereby enriching the interface display effect and improving the user experience.
[0117] An embodiment of the present invention further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method for displaying text vertically provided in the above embodiment are implemented.
[0118] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for displaying text vertically in the above embodiment are executed.
[0119] The computer program product provided in the embodiment of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be found in the method embodiment and will not be repeated here.
[0120] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0121] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0122] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.
[0123] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0124] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A method for displaying text vertically, characterized in that: Applied to the Android system, the method includes: Get the control property corresponding to the text control and the string property to be displayed corresponding to the string to be displayed; Based on the control attributes and the attributes of the string to be displayed, determine the target string and the maximum number of characters in each column; the target string is a string that can be fully displayed by the text control in the string to be displayed; Traversing the target character string, and setting corresponding character coordinates for each character in the target character string in a top-to-bottom order based on the maximum number of characters in each column and on the principle that the characters drawn in each column are fully arranged; The target character string is drawn in the text control according to the character coordinates and the attributes of the character string to be displayed.
2. The method for displaying characters vertically according to claim 1, characterized in that: The control attributes include control height and control width; the to-be-displayed string attributes include the number of characters to be displayed, the character height and character width corresponding to a single character; The step of determining the target string and the maximum number of characters in each column based on the control properties and the properties of the string to be displayed includes: Based on the control height and the character height, determining the quotient of the control height and the character height as the maximum number of characters per column; Based on the control width and the character width, determining the quotient of the control width and the character width as the maximum number of display columns; Based on the maximum number of characters per column and the maximum number of display columns, determining the product of the maximum number of characters per column and the maximum number of display columns as the maximum number of characters; Determining whether the number of characters to be displayed is less than or equal to the maximum number of characters; If yes, determining that the character string to be displayed is the target character string; If not, the character string to be displayed is segmented based on the maximum number of characters, and the segmented character string to be displayed is determined as the target character string.
3. The method for displaying characters vertically according to claim 1, characterized in that: The step of traversing the target character string and setting corresponding character coordinates for each character in the target character string in a top-to-bottom order based on the maximum number of characters in each column and on the principle that the characters drawn in each column are fully arranged comprises: S1: Set the horizontal coordinate of the character coordinate corresponding to the first character in the target string to 0, the vertical coordinate to 0, and set the initial value of the number of characters with coordinates in the current column to 1; S2: Obtain the current character without coordinates in the target character string, and determine whether the current character without coordinates is a preset line break character; S3: If the current character without coordinates is the preset line break character, determine that the next character of the current character without coordinates is the first character of the column, set corresponding character coordinates for the first character of the column according to a preset first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value; S4: if the current character without coordinates is not the preset line break character, determine that the current character without coordinates is a character in the column, set corresponding character coordinates for the character in the column according to the preset second coordinate setting rule, and add 1 to the number of characters with coordinates in the current column; determine whether the number of characters with coordinates is equal to the maximum number of characters in each column; if so, determine that the next character of the current character without coordinates is the first character of the column, set corresponding character coordinates for the first character of the column according to the first coordinate setting rule, and reset the number of characters with coordinates in the current column to the initial value; S5: Repeat steps S2-S4 until each character in the target character string is set with a corresponding character coordinate.
4. The method for displaying characters vertically according to claim 3, characterized in that: The attributes of the character string to be displayed include the character width corresponding to a single character; The first coordinate setting rule is to set the ordinate of the first character of the column to 0, and the abscissa to the sum of the abscissa corresponding to the previous character of the first character of the column and the character width.
5. The method for displaying characters vertically according to claim 3, characterized in that: The attributes of the character string to be displayed include the character height corresponding to a single character; The second coordinate setting rule is to set the horizontal coordinate of the character in the column to be the same as the horizontal coordinate corresponding to the previous character in the column, and the vertical coordinate is the sum of the vertical coordinate corresponding to the previous character and the height of the character.
6. The method for displaying characters vertically according to claim 1, characterized in that: The attribute of the string to be displayed includes a character color; the step of drawing the target string in the text control according to the character coordinates and the attribute of the string to be displayed includes: The target character strings are drawn one by one in the text control based on the character colors and the character coordinates.
7. The method for displaying characters vertically according to claim 1, characterized in that: Before the step of obtaining the control property corresponding to the text control, the method further includes: Create a custom initial text control; the initial text control inherits from the Android View class; In the initial text control, add a setText method to obtain the string to be displayed, add a requestLayout method to layout the initial text control, add an onMeasure method to set the control properties of the initial text control, and add an onDraw method to draw the received string to be displayed; Determine that the initial text control after adding the setText method, the requestLayout method, the onMeasure method, and the onDraw method is the text control.
8. A text vertical display system, characterized in that: Applied to the Android system, the system includes: The attribute acquisition module is used to acquire the control attribute corresponding to the text control and the string attribute to be displayed corresponding to the string to be displayed; A target string determination module, used to determine a target string and a maximum number of characters per column based on the control attributes and the to-be-displayed string attributes; the target string is a string that can be fully displayed by the text control in the to-be-displayed string; A character coordinate setting module, used for traversing the target character string, and setting corresponding character coordinates for each character in the target character string in a top-to-bottom order based on the maximum number of characters in each column and the principle that the characters drawn in each column are fully arranged; A drawing module is used to draw the target character string in the text control according to the character coordinates and the attributes of the character string to be displayed.
9. An electronic device, characterized in that: It comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and is characterized in that when the processor executes the computer program, the method for vertically displaying text as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method for displaying text vertically according to any one of claims 1 to 7 is implemented.
