CN112445551A - Method and device for solving automatic line feed problem of Textview control - Google Patents

Method and device for solving automatic line feed problem of Textview control Download PDF

Info

Publication number
CN112445551A
CN112445551A CN201910794760.7A CN201910794760A CN112445551A CN 112445551 A CN112445551 A CN 112445551A CN 201910794760 A CN201910794760 A CN 201910794760A CN 112445551 A CN112445551 A CN 112445551A
Authority
CN
China
Prior art keywords
text
line
width
textview
displayed
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910794760.7A
Other languages
Chinese (zh)
Inventor
黄�俊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
TD Tech Chengdu Co Ltd
Chengdu TD Tech Ltd
Original Assignee
Chengdu TD Tech Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu TD Tech Ltd filed Critical Chengdu TD Tech Ltd
Priority to CN201910794760.7A priority Critical patent/CN112445551A/en
Publication of CN112445551A publication Critical patent/CN112445551A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/451Execution arrangements for user interfaces

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The application discloses a method for solving the problem of automatic line feed of a Textview control, which comprises the following steps: acquiring the width of the Textview control, and measuring the total width of a text to be displayed; calculating the quotient of the total width of the text to be displayed and the width of the Textview control, and judging the number of lines required for displaying the text; the text of each line is drawn separately in left-to-right or right-to-left order, with the principle that the characters drawn in each line are full. The application also discloses a corresponding device. By applying the technical scheme disclosed by the application, the problem that the Textview control automatically changes the line when the line is not full can be solved.

Description

Method and device for solving automatic line feed problem of Textview control
Technical Field
The application relates to the technical field of android interface development, in particular to a method and a device for solving the problem of automatic line feed of a Textview control.
Background
One of the most common basic controls in android interface development is Textview, which is mainly used to undertake the task of text display and is inevitably used in almost all apps.
The friendly display of an application program (App) interface can lead a user to generate the most intuitive feeling for the App, namely, the direct relation between whether the user continues to be willing to use the application program is realized, and the importance of Textview as one of the most frequently used controls is self-evident. Therefore, it is important to be able to use the control most reasonably to achieve a most friendly display effect.
Currently, one problem with Textview provided by android native is: in a multi-line text display, the text contains Chinese and English or punctuation marks, and Textview may cause the text to automatically wrap lines without filling up one line. At present, no particularly perfect solution is provided for the problem, and only some special processing methods are provided for some display scenes. For example, characters of text in Textview are all-cornered, special characters are removed or all chinese labels are replaced with english labels, but these methods do not solve the above problems well.
The problems of Textview in multi-line text display mainly include:
(1) when TextView displays Chinese, punctuation cannot be displayed at the beginning and end of a line. If a punctuation mark is just at the end of a line, the punctuation mark is wrapped to the next line along with the previous character of the punctuation mark, resulting in the automatic wrapping without the previous line being full.
(2) When TextView displays english words, the words cannot be displayed in two different lines in a partitioned manner. If there is insufficient space left in a row to display the last english word in the row, the english word will be wrapped to the next row for display, which will result in the previous row being automatically wrapped without being fully wrapped, and there will be a blank space in the latter half of the previous row.
(3) When textView displays a Chinese, numeric and English mixed text, the problem of automatic line feed due to different front and rear character types exists.
The reason for the problem is that the native Textview control of the android system has technical defects for character processing of different languages.
To solve the above technical drawbacks, it is necessary to support the expected arrangement of Chinese, English, other languages, and special punctuation marks, etc., and each row is arranged as full as possible from left to right.
Disclosure of Invention
The application provides a method and a device for solving the automatic line feed problem of a Textview control, so that the number of characters capable of being displayed on a screen is larger.
The application discloses a method for solving the problem of automatic line feed of a Textview control, which comprises the following steps:
acquiring the width of the Textview control, and measuring the total width of a text to be displayed;
calculating the quotient of the total width of the text to be displayed and the width of the Textview control, and judging the number of lines required for displaying the text;
the text of each line is drawn separately in left-to-right or right-to-left order, with the principle that the characters drawn in each line are full.
Preferably, the method further comprises:
and if the number of lines required for displaying the text is larger than the total number of lines of the Textview space, inserting an ellipsis at the selected position, and omitting partial contents in the text.
Preferably, the drawing is implemented by controlling the display of the character by a method of inheriting the parent class by the child class and then rewriting the onDraw function.
The application also discloses a device for solving the problem of automatic line feed of the Textview control, which comprises the following steps: width acquisition module, judgement module and drawing module, wherein:
the width acquisition module is used for acquiring the width of the Textview control and measuring the total width of the text to be displayed;
the judging module is used for calculating the quotient of the total width of the text to be displayed and the width of the Textview control, and judging the line number required for displaying the text;
and the drawing module is used for independently drawing the text of each line according to the sequence from left to right or from right to left under the principle that the characters drawn by each line are all arranged fully.
Preferably, the rendering module is further configured to:
and when the number of lines required for displaying the text is larger than the total number of lines in the Textview space, inserting an ellipsis at the selected position, and omitting partial contents in the text.
Preferably, the drawing module is configured to control display of the character by a method of inheriting a parent class by a child class and then rewriting an onDraw function, so as to implement the drawing.
According to the technical scheme, the width of the Textview control is obtained, the total width of the text to be displayed is measured, the quotient of the total width of the text to be displayed and the width of the Textview control is calculated, and the number of lines required for displaying the text is judged; finally, under the principle that the characters drawn by each line are all arranged fully, the text of each line is drawn independently according to the sequence from left to right or from right to left, so that the problem that the Textview control automatically changes the line under the condition that the line is not arranged fully is solved, each line is arranged fully as much as possible, and the number of the characters capable of being displayed on the screen is more. For the private network terminal with the small screen, due to the fact that the interface display area is limited, the use experience of the terminal with the small screen can be well improved through the scheme provided by the invention.
Drawings
FIG. 1 is a schematic flow chart of a method for solving the problem of automatic line feed of a Textview control according to the present invention;
FIG. 2 is a schematic diagram of a structure of an apparatus for solving the problem of automatic line feed of a Textview control according to the present invention;
FIG. 3 is a schematic flow chart illustrating an embodiment of the present invention;
FIG. 4 is a schematic diagram illustrating an effect of displaying an English character string by using a native Textview control;
FIG. 5 is a schematic diagram illustrating an effect exhibited by displaying an English character string according to the present invention;
FIG. 6 is a diagram illustrating an effect of displaying a Chinese + English string using a native Textview control;
FIG. 7 is a diagram illustrating the effect of displaying the Chinese + English character string according to the present invention;
fig. 8 is a schematic diagram of the effect of processing a character string beyond 2 lines by using the scheme of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is further described in detail below by referring to the accompanying drawings and examples.
In order to solve the problems existing in the prior art, the invention provides a method for solving the problem of automatic line feed of a Textview control, which comprises the following steps as shown in fig. 1:
step 101: the width of the Textview control is obtained, and the total width of the text required to be displayed is measured.
Step 102: the quotient of the total width of the text to be displayed and the width of the Textview control (namely, the multiple relation between the total width and the width) is calculated, so as to judge the number of lines required for displaying the text.
Step 103: the text of each line is drawn separately in left-to-right or right-to-left order, with the principle that the characters drawn in each line are full.
On the basis of the method shown in fig. 1, if the number of lines required for displaying the text is greater than the total number of lines of the Textview control, that is, all lines filled with the Textview control cannot display the text completely, an ellipsis is inserted at a proper position according to the situation, and a part of the text is omitted.
The technical scheme provided by the invention not only can meet the special requirements of various different types of characters on display, but also can meet the friendly interface display.
Because the native text display method of the native Textview control of the android system is realized by calling the onDraw function, the method provided by the invention can realize the display control of the characters by a method of inheriting a parent class by a subclass and then rewriting the onDraw function, thereby solving the problem that the characters in the upper row are automatically changed when the characters in the upper row are not fully arranged in the multi-row display.
Corresponding to the above method, the present application further provides a corresponding virtual device, whose composition structure diagram is shown in fig. 2, including: width acquisition module, judgement module and drawing module, wherein:
the width acquisition module is used for acquiring the width of the Textview control and measuring the total width of the text to be displayed;
the judging module is used for calculating the quotient of the total width of the text to be displayed and the width of the Textview control, and judging the line number required for displaying the text;
and the drawing module is used for independently drawing the text of each line according to the sequence from left to right or from right to left under the principle that the characters drawn by each line are all arranged fully.
Further, the rendering module may be further configured to: and when the number of lines required for displaying the text is larger than the total number of lines in the Textview space, inserting an ellipsis at the selected position, and omitting partial contents in the text.
Preferably, the drawing module is configured to control display of the character by a method of inheriting a parent class by a child class and then rewriting an onDraw function, so as to implement the drawing.
The technical solution of the present application is further described in detail by a preferred embodiment.
In this embodiment, the display of a certain private network terminal is taken as an example: inputting any segment of character string text mixed with Chinese, English, numbers and punctuation marks, changing the line after one line is full, displaying 2 lines of text at most, and inserting ellipses at the beginning of the second line for scenes which cannot be displayed. The specific implementation flow for satisfying the above requirements by using the technical solution of the present invention is shown in fig. 3, and includes the following processes:
firstly, obtaining a layout and a brush, and obtaining the width X of a Textview control and the length Y of a text to be displayed;
then, judging whether the length Y of the text needing to be displayed is less than or equal to the width X of the Textview control:
if the judgment result is 'yes', the display of one line is indicated, and the processing is carried out according to the following mode a;
if the judgment result is 'no', the text cannot be completely displayed on one line, and whether the two lines can be completely displayed or not is continuously judged, namely: judging whether Y < ═ 2X is true, if so, indicating that two rows can be displayed completely, and processing according to the following mode b; otherwise, the text indicating that the text needs to be displayed exceeds two lines is processed in the following manner c.
Mode a, for the situation that the text can be displayed by one line, drawing the character string according to the following mode:
assuming that the index of the starting position of the text string is i and the ending position is j, all the strings from i to j are drawn, and the flow is ended.
And b, for the condition that the two lines can display the text, drawing the character string according to the following mode:
starting from the initial position index i of the text string, increasing the i, calculating the length of the string, and if the length of the string between i and i + + is less than the width X of the Textview control, performing i + +; if the length of the character string between i and i + + is equal to the width X of the Textview control, the text in the first line is drawn with the index of the starting position of the text character string as i and the end position as i + +, the text in the second line is drawn with the index of the position of the text character string as i + +, and the end position as j, and the process is ended.
Mode c, for the case that the text exceeds two lines to be displayed, drawing the character string according to the following mode:
drawing a first line of text, namely: drawing a character string from i to i + +;
drawing an ellipsis at the beginning of the second line;
judging whether the width of a character string between j and j is (the width of a Textview control-the width of an ellipsis) or not, and if not, carrying out j- -; if yes, drawing the rest character strings of the second row, namely the character strings between j and j, and ending the flow. Where j is the end position of the second row.
In the embodiment, on a private network terminal with a small screen, the interface display area is limited, and characters can be displayed as much as possible in 2 lines. The demonstration effect display by adopting the native Textview control and the technical scheme of the invention is shown in figures 4-8:
FIG. 4 is a schematic diagram illustrating an effect of displaying an English character string by using a native Textview control. According to fig. 4, when the english word "terminal" is not displayed in the first line, the display is directly switched to the second line, so that the first line is not full, and for the originally limited screen, the number of characters that can be displayed is less, and the special display requirement cannot be met.
FIG. 5 is a schematic diagram illustrating an effect exhibited by displaying an English character string according to the present invention. According to fig. 5, each line can be filled as much as possible by using the scheme of the invention, thereby enabling a larger number of words to be displayed on the screen.
FIG. 6 is a diagram illustrating the effect of displaying Chinese + English character strings by using a native Textview control. According to FIG. 6, for a mixed English and Chinese scene, the native Textview control is used to draw, resulting in the first line wrapping directly without being full.
FIG. 7 is a diagram illustrating the effect of displaying the Chinese + English character string according to the present invention. According to fig. 7, each line can be filled as much as possible by adopting the scheme of the invention, so that the number of words which can be displayed on the screen is more.
Fig. 8 is a schematic diagram of the effect of processing a character string beyond 2 lines by using the scheme of the present invention. According to fig. 8, in a scene that 2 lines of the screen can not display the character string completely, the ellipses can be inserted into the designated positions by adopting the scheme of the invention.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims (6)

1. A method for solving the problem of automatic line feed of a Textview control is characterized by comprising the following steps:
acquiring the width of the Textview control, and measuring the total width of a text to be displayed;
calculating the quotient of the total width of the text to be displayed and the width of the Textview control, and judging the number of lines required for displaying the text;
the text of each line is drawn separately in left-to-right or right-to-left order, with the principle that the characters drawn in each line are full.
2. The method of claim 1, further comprising:
and if the number of lines required for displaying the text is larger than the total number of lines of the Textview space, inserting an ellipsis at the selected position, and omitting partial contents in the text.
3. The method according to claim 1 or 2, characterized in that:
and controlling the display of the characters by a method of inheriting the parent class by the subclass and then rewriting the onDraw function, so as to realize the drawing.
4. An apparatus for solving the problem of automatic line feed of a Textview control, comprising: width acquisition module, judgement module and drawing module, wherein:
the width acquisition module is used for acquiring the width of the Textview control and measuring the total width of the text to be displayed;
the judging module is used for calculating the quotient of the total width of the text to be displayed and the width of the Textview control, and judging the line number required for displaying the text;
and the drawing module is used for independently drawing the text of each line according to the sequence from left to right or from right to left under the principle that the characters drawn by each line are all arranged fully.
5. The apparatus of claim 4, wherein the rendering module is further configured to:
and when the number of lines required for displaying the text is larger than the total number of lines in the Textview space, inserting an ellipsis at the selected position, and omitting partial contents in the text.
6. The apparatus of claim 4 or 5, wherein:
and the drawing module is used for controlling the display of the characters by a method of inheriting a parent class by a subclass and then rewriting an onDraw function, so as to realize the drawing.
CN201910794760.7A 2019-08-27 2019-08-27 Method and device for solving automatic line feed problem of Textview control Pending CN112445551A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910794760.7A CN112445551A (en) 2019-08-27 2019-08-27 Method and device for solving automatic line feed problem of Textview control

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910794760.7A CN112445551A (en) 2019-08-27 2019-08-27 Method and device for solving automatic line feed problem of Textview control

Publications (1)

Publication Number Publication Date
CN112445551A true CN112445551A (en) 2021-03-05

Family

ID=74740761

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910794760.7A Pending CN112445551A (en) 2019-08-27 2019-08-27 Method and device for solving automatic line feed problem of Textview control

Country Status (1)

Country Link
CN (1) CN112445551A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113033147A (en) * 2021-03-26 2021-06-25 北京字节跳动网络技术有限公司 Text processing method, device, equipment and medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110310103A1 (en) * 2010-06-18 2011-12-22 Hsiang Jieh Type-setting method for a text image file
CN102436439A (en) * 2010-09-29 2012-05-02 鸿富锦精密工业(深圳)有限公司 Text box and text display method
CN107783946A (en) * 2016-08-27 2018-03-09 上海卓易电子科技有限公司 Text display method and text display
CN108255801A (en) * 2018-01-19 2018-07-06 深圳市富途网络科技有限公司 A kind of Justified implementation methods of Android TextView
CN108710601A (en) * 2018-05-14 2018-10-26 广州腾讯科技有限公司 A kind of text display method and its equipment, storage medium, electronic equipment
CN110114748A (en) * 2017-10-09 2019-08-09 华为技术有限公司 A kind of display processing method and electronic equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110310103A1 (en) * 2010-06-18 2011-12-22 Hsiang Jieh Type-setting method for a text image file
CN102436439A (en) * 2010-09-29 2012-05-02 鸿富锦精密工业(深圳)有限公司 Text box and text display method
CN107783946A (en) * 2016-08-27 2018-03-09 上海卓易电子科技有限公司 Text display method and text display
CN110114748A (en) * 2017-10-09 2019-08-09 华为技术有限公司 A kind of display processing method and electronic equipment
CN108255801A (en) * 2018-01-19 2018-07-06 深圳市富途网络科技有限公司 A kind of Justified implementation methods of Android TextView
CN108710601A (en) * 2018-05-14 2018-10-26 广州腾讯科技有限公司 A kind of text display method and its equipment, storage medium, electronic equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
SIBERIADANTE: "TextView设置文字包含中英文时自动换行问题的终极解决方案", 《HTTPS://WWW.CNBLOGS.COM/SHEN-HUA/P/8489622.HTML》, 1 March 2018 (2018-03-01), pages 1 - 3 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113033147A (en) * 2021-03-26 2021-06-25 北京字节跳动网络技术有限公司 Text processing method, device, equipment and medium

Similar Documents

Publication Publication Date Title
CN101036137B (en) Display, display control method
CN103678267A (en) Method and system for typesetting and rendering image-text mixed content
CN112445551A (en) Method and device for solving automatic line feed problem of Textview control
CN104965813B (en) The treating method and apparatus of textual materials
CN108763188A (en) A kind of text display method, device, equipment and storage medium
CN109992188B (en) Method and device for realizing scrolling display of iOS mobile terminal text
CN106970746B (en) Title bar setting method and device
CN113377275A (en) Interface presentation method based on label
CN104516859B (en) A kind of word modification method and system
CN104090755A (en) Vertical scrolling display method for long application names in Android Launcher interface
CN111400998A (en) Text display method and device, electronic equipment and readable storage medium
CN111291533A (en) Sentence segment to be displayed display method and device, computer equipment and storage medium
CN110609981A (en) Text processing method and device, electronic equipment and computer readable storage medium
CN103123623A (en) Method and device for providing webpage hierarchy information
CN109308146B (en) Character string self-adaptive segmentation display method and system based on control attributes
CN106020813A (en) Application starting apparatus and method
CN106294305A (en) Android smart machine carries out, to html web page content, the method that segmentation shows
CN106445903A (en) Image-text data typesetting method and apparatus
US20210124869A1 (en) Font feature selection for text layout
CN104679723A (en) Text contrast display method, system and device
CN108363814B (en) Label setting method, server and label setting system
CN103324741B (en) A kind of webpage zoom on electronic equipment and the method and apparatus of alignment
CN113436298B (en) Method and device for automatically generating Chinese character stroke order animation and related components thereof
CN115525270A (en) Method, system, terminal device and storage medium for rendering form page based on dragging
CN108255801A (en) A kind of Justified implementation methods of Android TextView

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20210305

RJ01 Rejection of invention patent application after publication