Method and system for automatically adjusting character typesetting for Android smart television and computer readable medium
By setting a threshold width and dynamically modifying layout parameters in Android smart TVs, the character layout is automatically adjusted, solving the problem of visual imbalance in character controls and improving user experience and interface consistency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SICHUAN CHANGHONG ELECTRIC CO LTD
- Filing Date
- 2025-12-31
- Publication Date
- 2026-05-01
AI Technical Summary
When formatting text controls on Android smart TVs, there is a problem where the last line has too few characters to be automatically adjusted, resulting in a visual imbalance between lines with many characters and lines with few characters, and requiring complex manual adjustments.
By setting a threshold width, the required display width of the current character content is calculated. If the parent container allows, the properties of the view layout parameters are dynamically modified to adjust the width of each line of characters, thereby automatically adjusting the character layout and avoiding the occurrence of missing lines of characters.
It achieves visual balance in character layout, eliminates missing lines of text, improves user experience, avoids tedious manual adjustments, and is suitable for various interface character controls.
Smart Images

Figure CN121967772A_ABST
Abstract
Description
Methods, systems, and computer-readable media for automatically adjusting character layout in Android smart TVs Technical Field
[0001] This invention relates to the field of smart TV operating system technology, and in particular to a method, system, and computer-readable medium for automatically adjusting character layout in Android smart TVs. Background Technology
[0002] Character controls on smart TVs typically refer to user interface elements used to display, edit, and control text content on the TV screen. Common functions and uses include text display, text input, text editing, text selection and highlighting, text search, and text interaction.
[0003] Android smart TVs refer to smart TVs that run the Google Android operating system. Currently, in the layout of Android smart TV interfaces, character controls typically use a fixed width or automatic line wrapping, with the system calculating the width automatically to ensure complete display. The traditional execution method for these character controls is as follows: the width and height of the character control are determined when configuring the layout; line wrapping is performed automatically during drawing; and automatic line wrapping is executed when the width of the edited character or the character entered in the character control exceeds the maximum width.
[0004] Traditional character controls like TextView typically rely on fixed-width controls for layout. While they automatically wrap lines based on control width and font size to ensure complete character display, this process often results in isolated lines or characters. For example, a line might display only a few characters, yet still require a wrap, leading to a visual imbalance between lines with and without characters. Alternatively, while all characters can be displayed in one line, they may easily exceed the visible screen. Summary of the Invention
[0005] The purpose of this invention is to address the problem that existing methods for adjusting character layout in Android TVs only change the adaptive width of the control based on the character length. This results in difficulties in automatically adjusting the last line due to its smaller number of characters compared to the preceding lines, leading to visual imbalance between lines with many or few characters and making manual adjustment of layout settings and editing complex. The invention provides a method, system, and computer-readable storage medium for automatically adjusting character layout in Android smart TVs.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] A method for automatically adjusting character layout for Android smart TVs includes the following steps:
[0008] S1. Get the initial width of the character control; set the threshold width;
[0009] S2. Calculate the required display width of the current character content. If the required display width of at least one line of the current character content displayed by the character control is less than the threshold width, then trigger character reformatting. If the required display width of each line of the current character content displayed by the character control is greater than or equal to the threshold width, then do not trigger character reformatting.
[0010] S3. Perform the character reformatting: Determine if the required display width can be increased in the parent container; if it can, dynamically modify the view layout parameters. If it cannot, do not dynamically modify the view layout parameters.
[0011] The method for automatically adjusting character layout for Android smart TVs described in this invention sets a threshold width and calculates the required display width of the current character content. If at least one line has a required display width less than the threshold width, automatic layout is triggered. If the required display width can be achieved in the parent container, allowing adjustment of the character width of each line, the properties of the view layout parameters are dynamically modified to adjust the required display width to accommodate lines with smaller required display widths, thus avoiding lines with insufficient required display width, such as lines with only one character. This achieves automatic adjustment of character layout, eliminates lines with insufficient character width, improves the character layout of the character control, and enhances the user experience.
[0012] Preferably, in the method for automatically adjusting character layout for Android smart TVs according to the present invention, the threshold width is set to less than 10% of the initial width.
[0013] As a preferred embodiment of the present invention, by setting the threshold range to less than 10% of the initial width, the occurrence of characters occupying 10% of the entire line of characters can be strictly controlled, thereby improving the accuracy of automatic character layout adjustment. Even when the font is small, the possibility of missing characters occupying a line is further reduced, thus optimizing the character layout scheme.
[0014] Preferably, the method for automatically adjusting character layout for Android smart TVs according to the present invention, wherein determining whether the required display width can be increased in the parent container specifically includes the following steps:
[0015] Detect the width of the parent container and the screen; call the getParent() recursive algorithm to calculate the first remaining width of the parent container and the second remaining width of the screen; if both the first remaining width and the second remaining width are greater than the required display width, then determine that the required display width can be increased in the parent container.
[0016] As a preferred embodiment of the present invention, the width of the parent container and the screen are detected, and then the first remaining width and the second remaining width are calculated by a recursive algorithm. The remaining space on the right side of the parent container is recursively calculated. Finally, the distance from the control to the right edge of the screen is combined to determine whether the remaining space can completely display the content of the line break in one line. This reduces the possibility that the character control may exceed the boundary of the parent container or the screen boundary due to the adjustment of character layout, and improves the reliability of adjusting character layout.
[0017] Preferably, the method for automatically adjusting character layout for Android smart TVs according to the present invention calculates the required display width of the current character content, specifically including the following steps:
[0018] The Paint.measureText() algorithm is used to calculate the display width of each character in the character control, and then the widths of all characters are added together to obtain the required display width of the current character content.
[0019] As a preferred embodiment of the present invention, by calculating the required display width of the current character content, the required display width of the current character content can be obtained more accurately, thereby improving the accuracy of character layout.
[0020] Preferably, the method for automatically adjusting character layout for Android smart TVs according to the present invention, in obtaining the initial width of the character control, specifically includes the following steps:
[0021] Calculate the boundary distance from the control boundary to the parent container boundary of the character control before the adaptive width change, and then obtain the maximum width as the initial width of the character control.
[0022] As a preferred embodiment of the present invention, the initial width can be obtained more quickly through the above specific method, reducing computational memory and improving efficiency.
[0023] Preferably, in the method for automatically adjusting character layout for Android smart TVs according to the present invention, step S2 further includes the following steps: when an automatic line break event is detected in the current character content, the character length of the last line is calculated; if the character length of the last line is less than the threshold width, then character rearrangement is triggered.
[0024] As a preferred embodiment of the present invention, by adding a specific automatic line wrapping event, it is only necessary to calculate the character length of the last line and perform a threshold width comparison to determine whether to trigger character reformatting. This can reduce the computational memory for displaying character content in all character controls, and can respond promptly to the user's input character beautification and layout requirements, further optimizing the efficiency of the method for adjusting character layout.
[0025] To achieve the objectives of this invention, another technical solution is provided:
[0026] An automatic character layout system for Android smart TVs, capable of implementing the above-mentioned method for automatically adjusting character layout, includes a character length detection module, a control width detection module, an algorithm execution module, and a character rearrangement module;
[0027] The character length detection module is used to detect the length of the input character in the character control, thereby obtaining the required display width of the character; the control width detection module is used to obtain the initial width of the character control, the width of the parent container, and the width of the TV screen; the algorithm execution module is used to calculate the required display width and compare the required display width with the threshold width; the character reformatting module is used to perform reformatting of the character control.
[0028] The automatic character layout system for Android smart TVs described in this invention, through the cooperation of the aforementioned modules, automatically detects the required display width of the user-input characters and determines whether to trigger a rearrangement based on the required display width. Under the condition that the TV screen and parent container allow it, by executing character rearrangement, it can achieve adaptive width display of fixed character controls. This avoids the situation where only a few characters are displayed in the last line, resulting in a large blank space. It reduces the blank space compared to lines with fewer characters, making the overall layout more harmonious and visually balanced. No manual width adjustment is required; the controls can automatically adjust the character layout according to the parent container and screen boundaries, and it can be used in various interface character controls of Android TV systems.
[0029] To achieve the objectives of this invention, another technical solution is also provided:
[0030] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the method for automatically adjusting character layout for an Android smart TV.
[0031] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:
[0032] 1. The method for automatically adjusting character layout for Android smart TVs described in this invention sets a threshold width and calculates the required display width of the current character content. If at least one line has a required display width less than the threshold width, automatic layout is triggered. If the required display width can be achieved in the parent container, the character width of each line can be adjusted. By dynamically modifying the properties of the view layout parameters, the required display width can be adjusted to accommodate lines of characters with smaller required display widths, thus avoiding lines of characters with insufficient required display width. This achieves automatic adjustment of character layout, eliminates lines of characters with fewer characters, beautifies the character layout of the character control, and improves the user experience.
[0033] 2. The automatic character layout system for Android smart TVs described in this invention can achieve adaptive width display of fixed character controls, avoiding the situation where only a few characters are displayed in the last line, resulting in a large blank space. This makes the visual balance between multiple and few lines of text in the text display interface more balanced, the overall layout more harmonious, and the visual balance stronger. It solves the problems of cumbersome manual adjustment steps and complex settings. There is no need to manually adjust the width. The control can automatically adjust the character layout according to the parent container and the screen boundary, and it can be used in various interface character controls of Android TV systems. Attached Figure Description
[0034] Figure 1 is a flowchart of the method for automatically adjusting character layout for Android smart TVs according to the present invention;
[0035] Figure 2 is a schematic diagram of the module connection of the automatic character layout system for Android smart TVs of the present invention;
[0036] Figure 3 is a schematic diagram of the execution process of the automatic character layout system for Android smart TVs of the present invention. Detailed Implementation
[0037] The present invention will now be described in detail with reference to the accompanying drawings.
[0038] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0039] Example 1:
[0040] Referring to Figure 1, the method for automatically adjusting character layout for Android smart TVs disclosed in this embodiment includes the following steps:
[0041] S1. Get the initial width of the character control; set the threshold width;
[0042] S2. Calculate the required display width of the current character content. If the required display width of at least one line of the current character content displayed by the character control is less than the threshold width, then trigger character reformatting. If the required display width of each line of the current character content displayed by the character control is greater than or equal to the threshold width, then character reformatting will not be triggered.
[0043] S3. Perform character reformatting: Determine if the required display width can be increased in the parent container; if the required display width can be increased in the parent container, dynamically modify the view layout parameter properties; if the required display width cannot be increased in the parent container, do not dynamically modify the view layout parameter properties.
[0044] It should be noted that the aforementioned dynamic modification of view layout parameters, such as dynamically modifying the LayoutParams.width property and executing requestLayout, is understood in this invention as follows: LayoutParams is a class used in Android development to define view layout parameters, and the LayoutParams.width property is a member variable of the LayoutParams class, used to specify the width of the view.
[0045] The `requestLayout` method of this invention is understood to be a frequently used method in Android development, typically related to view layout. Its main function is to request a layout change. When the `requestLayout()` method is called, it marks the current view and its parent view as needing a layout change, and then rearranges the views at an appropriate time.
[0046] The threshold width of this invention is understood as the maximum width of the character control that can be displayed per line of text. Specifically, the threshold width is set to less than 10% of the initial width, and the maximum width can be the fixed width initially given to the control.
[0047] Specifically, determining whether the required display width can be increased in the parent container involves the following steps: detecting the width of the parent container and the screen; calling the getParent() recursive algorithm to calculate the first remaining width of the parent container and the second remaining width of the screen; if both the first and second remaining widths are greater than the required display width, then it is determined that the required display width can be increased in the parent container. For example, if the width of the last line of characters is less than a set threshold, getParent() is called recursively to calculate the remaining width, and finally, the remaining width from the right margin of the screen is calculated.
[0048] Specifically, a control can obtain its parent control using `getParent`, and the parent control can obtain its width using `getWidth`. The current control can obtain its x-coordinate with the top-left corner of the parent layout as the furthest point using `getRight`. `parent.getWidth - this.getRight` is the right margin. It's important to note that the `getParent()` method is used in Android development to obtain the parent view of a view for more complex view operations and layout adjustments; the parent container is understood as the parent or top-parent character control, such as a TextView or a custom control.
[0049] Specifically, calculating the required display width of the current character content involves the following steps: Using the Paint.measureText() algorithm, calculate the display width of each character within the character control, and then sum all the character widths to obtain the required display width of the current character content. For example, Paint.measureText() can calculate the width required for each character to be displayed in the control (width can be understood as pixels), and then summing the total widths gives the total width required to display the content.
[0050] For example, during the rendering phase of a control, the maximum width of the text that the control can display can be dynamically calculated in the onMeasure() or onLayout() method; the width of the text content that needs to be displayed can be calculated using Paint.measureText().
[0051] The present invention obtains the initial width of a character control by recording the initial control width in the character control's onMeasure and onLayout methods, or by specifically including the following steps: calculating the boundary distance from the control's boundary to the parent container's boundary before the adaptive width change, and then obtaining the maximum width as the initial width of the character control. For example, by overriding the onMeasure() method, the initial width of the control and the measured width of the text can be calculated.
[0052] Specifically, S2 also includes the following steps: when an automatic line wrapping event is detected in the current character content, the character length of the last line is calculated; if the character length of the last line is less than the threshold width, the character is re-formatted.
[0053] Example 2:
[0054] Referring to Figures 1 and 2, this embodiment, based on Embodiment 1, discloses an automatic character layout system for Android smart TVs. Referring to Figure 3, it can realize the automatic character layout adjustment method for Android smart TVs of Embodiment 1, including a character length detection module, a control width detection module, an algorithm execution module, and a character rearrangement module. The character length detection module is used to detect the length of the input character in the character control, thereby obtaining the required display width of the character. The control width detection module is used to obtain the initial width of the character control, the width of the parent container, and the width of the TV screen. The algorithm execution module is used to calculate the required display width and compare the required display width with the threshold width. The character rearrangement module is used to perform the rearrangement of the character control.
[0055] Example 3:
[0056] Based on Embodiment 1, this embodiment discloses a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it performs the method for automatically adjusting character layout for an Android smart TV as described in the embodiment.
[0057] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for automatically adjusting character layout in Android smart TVs, characterized in that, The steps include: S1, obtaining the initial width of the character control; setting a threshold width; S2, calculating the required display width of the current character content; if the required display width of at least one line of the current character content displayed by the character control is less than the threshold width, then triggering character rearrangement; S3, performing the character rearrangement: determining whether the required display width can be increased in the parent container; if the required display width can be increased in the parent container, then dynamically modifying the properties of the view layout parameters.
2. The method for automatically adjusting character layout for Android smart TVs according to claim 1, characterized in that, The threshold width is set to less than 10% of the initial width.
3. The method for automatically adjusting character layout for Android smart TVs according to claim 1, characterized in that, The determination of whether the required display width can be increased in the parent container specifically includes the following steps: detecting the width of the parent container and the screen; calling the getParent() recursive algorithm to calculate the first remaining width of the parent container and the second remaining width of the screen; if both the first remaining width and the second remaining width are greater than the required display width, then it is determined that the required display width can be increased in the parent container.
4. The method for automatically adjusting character layout for Android smart TVs according to claim 1, characterized in that, The calculation of the required display width of the current character content includes the following steps: using the Paint.measureText() algorithm, calculate the display width of each character in the character control, and then add up the widths of all characters to obtain the required display width of the current character content.
5. The method for automatically adjusting character layout for Android smart TVs according to claim 1, characterized in that, Obtaining the initial width of a character control specifically includes the following steps: calculating the boundary distance from the control boundary to the parent container boundary before the adaptive width change, and then obtaining the maximum width as the initial width of the character control.
6. The method for automatically adjusting character layout for Android smart TVs according to any one of claims 1-5, characterized in that, The S2 further includes the following steps: when an automatic line wrapping event is detected in the current character content, the character length of the last line is calculated; if the character length of the last line is less than the threshold width, the character is re-formatted.
7. An automatic character formatting system for Android smart TVs, characterized in that, The method for automatically adjusting character layout for Android smart TVs as described in any one of claims 1-6 includes a character length detection module, a control width detection module, an algorithm execution module, and a character rearrangement module; the character length detection module is used to detect the length of the input character in the character control, thereby obtaining the required display width of the character; the control width detection module is used to obtain the initial width of the character control, the width of the parent container, and the width of the TV screen; The algorithm execution module is used to calculate the required display width and compare the required display width with the threshold width; the character reformatting module is used to perform reformatting of the character control.
8. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, performs the method for automatically adjusting character layout for an Android smart TV as described in any one of claims 1-6.