Screen adaptation implementation method of terminal equipment, equipment and medium
The layout file is loaded dynamically by defining component sizes and target screen parameters through density-independent pixels, combining layout dependencies and device clustering, and efficient and unified display effect of terminal device screen adaptation is achieved, solving the problems of low development efficiency and inconsistent display in terminal device screen adaptation.
Patent Information
- Application Number
- CN202510530568.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-07-18
AI Technical Summary
The prior art has problems such as inefficient development efficiency and inconsistent layout and display effects in the adaptation of terminal devices in the screen, which affects user experience and market competitiveness.
The component size is defined by density-independent pixels, the layout file is loaded dynamically through the target screen parameters, the component position attributes are determined using layout dependencies, and the percentage layout library and device clustering are combined to realize the adaptation of application components under different screen parameters.
It significantly reduces the workload of repeated development, improves adaptation efficiency, ensures the consistency and user experience of the application interface on different terminal devices, and solves the adaptation problems caused by screen fragmentation.
Smart Images

Figure CN120335925A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of terminal devices, and specifically relates to a method, device, and medium for realizing screen adaptation of a terminal device. Background Art
[0002] With the continuous development of the terminal device market, various brands and models of terminal devices emerge in an endless stream, and there are differences in their screen sizes, resolutions, and pixel densities. When developing terminal applications, how to adapt terminal applications to different types of screens has become an urgent problem to be solved. Traditional screen adaptation methods usually perform hard coding for specific screen sizes and resolutions, which not only has low development efficiency but also is difficult to cover all terminal devices. Once a new screen specification appears, developers need to spend a lot of time and effort to adapt and adjust the application. In addition, under different screen sizes and resolutions, it is difficult to unify the layout and display effects of terminal applications, which will seriously affect the user experience and reduce the market competitiveness of the application. Summary of the Invention
[0003] To solve the above problems, this application proposes a method for realizing screen adaptation of a terminal device, including: Determine the application component information to be loaded into the terminal device; wherein, the application component information includes the component size of the application component, and the component size is defined according to density-independent pixels; Determine the target screen parameters corresponding to the terminal device, and load the target layout file corresponding to the application component according to the target screen parameters; Determine the position attribute of the application component according to the layout dependency relationship set in the target layout file; Based on the position attribute and the component size, display the application component on the screen of the terminal device to achieve the adaptation of the application component among terminal devices with different screen parameters.
[0004] In an implementation manner of this application, before loading the target layout file corresponding to the application component according to the target screen parameters, the method further includes: For terminal devices with different screen parameters, determine the layout dependency relationship corresponding to the terminal device; wherein, the layout dependency relationship is a relative layout dependency or a constraint layout dependency; Construct the layout file corresponding to the terminal device according to the layout dependency relationship.
[0005] In an implementation manner of this application, constructing the layout file corresponding to the terminal device according to the layout dependency relationship specifically includes: Construct the layout file corresponding to the terminal device according to the layout dependency relationship; In the configuration file corresponding to the layout item of the terminal device, add a dependency on the percentage layout library, and set the layout attributes in the layout file to percentage layout attributes, so as to layout the application components according to the screen ratio through the percentage layout attributes.
[0006] In an implementation manner of the present application, after constructing the layout file corresponding to the terminal device according to the layout dependency relationship, the method further includes: Obtain screen parameters from a preset screen information database; wherein, the screen parameters include resolution; Cluster different terminal devices corresponding to the screen parameters according to the resolution, so as to divide the terminal devices into several device categories; Under the resource directory of the layout item, create resource folders corresponding to different device categories according to the layout file.
[0007] In an implementation manner of the present application, loading the target layout file corresponding to the application component according to the target screen parameters specifically includes: Determine the target device category to which the terminal device belongs according to the target screen parameters; According to the reference path of the resource folder, obtain the target layout file corresponding to the target device category from the resource directory, and load the target layout file corresponding to the application component.
[0008] In an implementation manner of the present application, determining the position attribute of the application component according to the layout dependency relationship set in the target layout file specifically includes: Determine the layout dependency relationship set in the target layout file; In the case where the layout dependency relationship is a relative layout dependency, determine the position attribute of the application component according to the relative positions between the application components; In the case where the layout dependency relationship is a constraint layout dependency, determine the position attribute of the application component according to the constraint relationship between the application components.
[0009] In an implementation manner of the present application, displaying the application component on the screen of the terminal device based on the position attribute and the component size specifically includes: Detect the screen folding state of the terminal device through a sensor provided in the terminal device; Determine the visible area of the terminal device according to the screen folding state; Based on the position attribute and the component size, display the application component in the visible area.
[0010] In one implementation of the present application, before obtaining screen parameters from a preset screen information database, the method further includes: Collect screen parameters corresponding to terminal devices of different device models from a preset device data source at a preset collection interval; Construct a screen information database according to the screen parameters.
[0011] An embodiment of the present application provides a screen adaptation implementation device for a terminal device, and the device includes: At least one processor; And a memory communicatively connected to the at least one processor; Wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a screen adaptation implementation method for a terminal device as described in any one of the above.
[0012] An embodiment of the present application provides a non-volatile computer storage medium storing computer-executable instructions, and the computer-executable instructions are set as: A screen adaptation implementation method for a terminal device as described in any one of the above.
[0013] A screen adaptation implementation method for a terminal device proposed by the present application can bring the following beneficial effects: Using density-independent pixels to define component sizes decouples the visual size of components from physical pixels, avoiding separately hard-coding size parameters for different screen densities, enabling developers to only maintain a set of size standards based on logical units, and significantly reducing the repetitive workload. Dynamically loading layout files through target screen parameters and determining component position attributes using layout dependencies replaces the traditional hard-coded positioning method for specific resolutions, transforming the adaptation work from writing specific code for each device to automatic adaptation after defining rules. This not only reduces the amount of code modification when adapting to new devices but also realizes batch adaptation support for similar devices through device clustering and resource classification management, significantly improving the adaptation efficiency and solving the screen adaptation problem caused by terminal device fragmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The drawings described herein are used to provide a further understanding of the present application, form a part of the present application, and the illustrative embodiments and descriptions thereof of the present application are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings: Figure 1 It is a flowchart of a screen adaptation implementation method for a terminal device provided by an embodiment of the present application; Figure 2Schematic diagram of the structure of a screen adaptation implementation device for a terminal device provided by an embodiment of the present application. Detailed implementation manners
[0015] To make the objectives, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.
[0016] The following will detail the technical solutions provided by each embodiment of the present application in conjunction with the drawings.
[0017] As Figure 1 shown, a screen adaptation implementation method for a terminal device provided by an embodiment of the present application includes: S101: Determine the application component information to be loaded into the terminal device; wherein, the application component information includes the component size of the application component, and the component size is defined according to density-independent pixels.
[0018] An application component is the basic unit that constitutes the user interface of a terminal application, and includes visual elements such as buttons, text boxes, image views, list views, etc. When an application component adapts to different screens, it is first necessary to determine the application component information to be loaded on the terminal device, and this application component information is used to determine the size attributes of the application component. The application component information includes the component size of the application component, and the component size is defined according to density-independent pixels. Setting the size of the component according to density-independent pixels (dp), regardless of the pixel density of the terminal device, the visual size of the application component on the screen is basically the same. Compared with directly using the pixel (px) unit, the dp unit can effectively avoid display problems caused by differences in screen pixel density.
[0019] When a user starts an application on a terminal device, the application program first reads the screen parameter information of the device to obtain the screen size, resolution and pixel density of the current device. Based on the generated component configuration file, using the unit conversion mechanism provided by the operating system, the component size parameter in dp units is converted into the physical pixel size applicable to the current device. Through this dynamic conversion process, it is ensured that the application component can be rendered in the correct size and layout on different terminal devices, effectively solving the compatibility problems existing in traditional adaptation solutions and achieving a consistent display effect of the application interface in a multi-device environment.
[0020] S102: Determine the target screen parameters corresponding to the terminal device, and load the target layout file corresponding to the application component according to the target screen parameters.
[0021] Different terminal devices have different corresponding screen parameters, and the screen parameters at least include screen size, resolution, and pixel density. When an application component is displayed, it needs to adapt to different screen parameters. During the development stage of an application, when facing different models of terminal devices, if the adaptation code is repeatedly written for different screen specifications, the development efficiency is relatively low. In the embodiments of the present application, layout files are designed for different specifications of terminal devices. By uniformly calling the layout files and utilizing the layout dependency relationships set in the layout files, the layout relationships between application components can be flexibly adjusted, reducing the repetitive adaptation limitations brought by traditional hard coding. Therefore, after the information of the application components that need to be adapted is determined, it is necessary to determine the target screen parameters corresponding to the currently used terminal device, and then, according to the target screen parameters, select the target layout file corresponding to the application component from the already designed layout files. It should be noted that the layout files are classified and designed according to the resolution. When selecting the target layout file, it is necessary to load the corresponding layout resources according to the resolution of the terminal device.
[0022] In one embodiment, before loading the target layout file, it is necessary to configure the layout file so that when laying out the application components, the appropriate layout file can be directly selected according to the used terminal device, without the need to perform hard coding for each model of terminal device. Just select the appropriate layout file according to the resolution to achieve the screen adaptation of the application components on different terminal devices, effectively reducing the development efficiency.
[0023] Before configuring the layout file, it is first necessary to perform a systematic screen parameter collection work on the target terminal device. According to the preset collection interval, collect the screen parameters corresponding to the terminal devices of different device models from the preset device data sources. Here, the device data sources include data sources such as the official websites of device manufacturers, electronic product evaluation websites, and public device databases. The collected screen parameters include screen size, screen resolution, and pixel density. According to the collected screen parameters, construct a screen information database corresponding to the terminal device. This database serves as the basic data support for subsequent adaptation work and provides an accurate technical basis for formulating adaptation strategies.
[0024] After the construction of the screen information database is completed, the layout file needs to be configured. When configuring the layout file, the absolute layout method is no longer used. Instead, for terminal devices with different screen parameters, the corresponding layout dependency relationship of the terminal device is determined. Among them, the layout dependency relationship is relative layout dependency or constraint layout dependency. The relative layout dependency determines the position of components by defining the relative positions between components. For example, a certain component is located above, below, to the left, or to the right of another component, etc. The constraint layout dependency sets the constraint conditions between components and the parent container or other components, such as a fixed distance from the boundary, an alignment relationship with other components, etc. Through different layout dependency relationships, the component layout can be controlled more flexibly to adapt to changes in different screen sizes and resolutions. After determining the layout dependency relationship, according to the selected layout dependency relationship, the layout dependency relationship between application components is written according to specific syntax and format to generate the corresponding layout file.
[0025] In one embodiment, when generating the layout file, although the layout dependency relationship can achieve layout adaptation of the application interface on different terminal devices to a certain extent, the traditional fixed-value layout method still has limitations. The screen sizes and resolutions of different terminal devices vary greatly. Even if relative layout or constraint layout is used, the fixed-value layout settings are difficult to ensure that the application can present a perfect layout effect on all devices. For example, the appropriate size and position set on a small-screen device may appear too small or in the wrong position on a large-screen device. The percentage layout library is a tool library specifically used to implement the layout of the application interface according to the screen ratio. With the help of this library, the application can dynamically adjust the component layout according to the actual size of the screens of different terminal devices to ensure that the interface can maintain good visual proportions and coordination under various screen sizes, effectively improving the adaptability and user experience of the application. Therefore, after the layout file is constructed, by adding the percentage layout library dependency and setting the percentage layout attributes, the application layout is further optimized to solve the problem of imperfect layout adaptation under different screen sizes and improve the display effect and user experience of the application on various terminal devices.
[0026] In the Android Studio development environment, in order to be able to use the functions of the percentage layout library, it is necessary to add a dependency on the percentage layout library in the configuration file corresponding to the layout project of the terminal device. The configuration file, that is, the build.gradle file, is used to record various resources and dependency relationship information required by the project and is an important configuration basis for the construction and operation of the application project. By adding the dependency, the application project can obtain and use the functions provided by the percentage layout library during the construction and operation process for subsequent percentage layout.
[0027] After adding the dependency of the percentage layout library, it is also necessary to modify the layout attributes in the constructed layout file and convert them into percentage layout attributes. The percentage layout attributes include layout_widthPercent, layout_heightPercent, etc. By setting the layout attributes as percentage layout attributes, when the application runs, it will automatically calculate and adjust the specific positions and sizes of each application component according to the actual size of the terminal device screen and in combination with the functions of the percentage layout library, effectively solving the problem of inconsistent layouts under different screen sizes and ensuring that the application interface can present a good display effect on various terminal devices.
[0028] In one embodiment, there is a serious problem of screen parameter fragmentation in the terminal device market. For devices of different brands and models, their screen resolutions, sizes, and pixel densities vary greatly. If separate adaptation development is carried out for the screen parameters of each device, it will not only greatly increase the development cost but also lead to chaotic resource management and problems such as file redundancy. Therefore, after constructing the layout file corresponding to the terminal device according to the layout dependency relationship, it is necessary to group devices with similar resolutions into one category through device clustering to achieve an adaptation mode where each category of devices is adapted to one category of resources. Thus, when calling the layout file later, only by clarifying which category of device the terminal device belongs to can the corresponding layout file be obtained, effectively reducing repetitive development work and improving the adaptation efficiency.
[0029] Specifically, obtain the screen parameters from the screen information database, and then use a machine learning library in Python, such as Scikit-learn, to perform clustering analysis on different terminal devices corresponding to each screen parameter according to the resolution. Specifically, the K-Means clustering algorithm can be used to divide the terminal devices into several device categories, such as low-resolution devices, medium-resolution devices, high-resolution devices, etc. After completing the device clustering, in order to enable the application to automatically load the appropriate layout file according to the device category during runtime, effective physical storage management of the layout file is required. Therefore, in the resource directory corresponding to the layout project, that is, the res directory, create corresponding resource folders according to the divided device categories. For example, if the device categories are divided into low-resolution category, medium-resolution category, and high-resolution category, then create folders such as layout - sw480p, layout - sw720p, layout - sw1080p, etc. Then, put the previously constructed layout files into the corresponding folders according to the device categories.
[0030] In one embodiment, when the application runs on the terminal device, the server automatically obtains the target screen parameters of the terminal device, matches the corresponding target device category according to the target screen parameters, and then obtains the target layout file corresponding to the target device category from the resource directory according to the reference path of the resource folder. By loading the target layout file, the precise adaptation of the application program interface layout to the device screen parameters is achieved. Through the mapping relationship between the device category and the layout resources, the application can quickly and accurately find and use the adaptation resources, avoiding complex real-time calculations, improving the adaptation efficiency and stability of the application, and also facilitating subsequent resource maintenance and updates.
[0031] S103: Determine the position attribute of the application component according to the layout dependency set in the target layout file.
[0032] After loading the target layout file through the above steps, the target layout file is parsed to extract the layout dependencies set therein. According to the relative layout dependencies or constraint layout dependencies obtained by parsing, combined with the screen parameters of the terminal device, the position attribute of each application component is determined. The position attribute is used to describe the specific coordinate position of the application component on the screen.
[0033] Specifically, determine whether the layout dependency set in the target layout file is a relative layout dependency or a constraint layout dependency. In the case where the layout dependency is a relative layout dependency, determine the position attribute of the application component according to the relative positions between the application components. Extract the relative position descriptions between the application components from the layout file. For example, button A is located above text box B, with a distance of 10 dp. Starting from a certain reference component, combined with the screen parameters of the terminal device, gradually deduce and calculate to determine the position attributes of other components. During the calculation process, it is necessary to convert the distance in dp to the actual physical pixel value.
[0034] In the case where the layout dependency is a constraint layout dependency, determine the position attribute of the application component according to the constraint relationships between the application components. Obtain all the constraint conditions regarding the application components from the layout file. For example, text box E is 15 dp away from the top boundary of the parent container, and button F is horizontally centered with image view G. According to the screen parameters of the terminal device, perform comprehensive calculations in combination with these constraint conditions.
[0035] It should be noted that the calculation process needs to consider the mutual influence among multiple constraint conditions simultaneously. When the position of a component is subject to multiple alignment and distance constraints, it is necessary to find the coordinate values that satisfy all the constraint conditions through mathematical calculations and logical reasoning. Taking the constraint condition that the distance between Picture C and the left boundary of the parent container is 20 dp and it is aligned with the right boundary of Button D as an example, first, determine the starting position of Picture C in the horizontal direction according to the width of the parent container and the distance requirement of 20 dp. Then, further accurately determine the ending position of Picture C in the horizontal direction by obtaining the right boundary coordinates of Button D, so as to completely determine its horizontal position attribute. In the vertical direction, calculations are also carried out based on the relevant constraint conditions. In this way, the complex constraint relationships in the constraint layout file are transformed into specific position coordinates to achieve the precise positioning of application components on the screen.
[0036] S104: Based on the position attribute and the component size, display the application component on the screen of the terminal device to achieve the adaptation of the application component among terminal devices with different screen parameters.
[0037] After determining the position attribute and component size of the application component, it is necessary to display the application component on the screens of terminal devices with different screen parameters based on the position attribute and component size, so as to achieve the adaptation of the same application on the screens of different terminal devices. It should be noted that since the position attribute and component size mentioned above are both defined based on dp, and in actual display, they need to be converted into physical pixel values that can be recognized by the terminal device. Therefore, when displaying the application component on the screen, it is also necessary to perform unit conversion on the position attribute and component size of the application component according to the screen situation of the current device.
[0038] In one embodiment, for some special terminal devices, such as foldable screen devices, it is impossible to adapt to the dynamic adjustment of the visible area after the screen state change of the foldable screen device only based on fixed screen parameters and position attributes. If the application cannot be adapted and displayed according to the screen folding state, problems such as incomplete display of components and layout disorders may occur. For example, when the device switches from the unfolded state to the folded state, the application components that were originally normally displayed on the full screen may be blocked or displayed abnormally due to the smaller visible area.
[0039] Specifically, sensors such as angle sensors and Hall sensors set on the terminal device are required to detect the screen folding state of the terminal device in real time. The angle sensor can measure the folding angle of the screen, while the Hall sensor can detect whether the screen is in a closed state. After obtaining the screen folding state, determine the visible area of the terminal device in this state. Specifically, it can be calculated based on the current folding angle and the screen size. After clarifying the visible area, according to the previously determined position attributes and component sizes of the application components, combined with the range of the current visible area, adjust and layout the display of the components. First, it is necessary to determine whether the application component is within the visible area based on its position attributes. If part or all of the application component exceeds the visible area, the position of the application component needs to be adjusted according to certain rules. For example, move the exceeded part back into the visible area, or scale the application component according to the size of the visible area. For the component size, ensure that the component is displayed in an appropriate size within the visible area according to the size and proportion of the visible area. Then, during the display process, it is necessary to monitor the change of the screen folding state in real time. Once the screen state change is detected, the above process will be executed again to determine the visible area and adjust the component display again, so as to achieve the dynamic adaptation and smooth display of the application components in different usage states of the folding screen device. Determining the visible area through the screen folding state and combining the position attributes and sizes of the application components for display effectively solves the problem of application adaptation for folding screen devices, provides a stable and high-quality application experience for users in different usage scenarios, and also provides strong support for the development of applications in the folding screen device market.
[0040] The above is the method embodiment proposed by this application. Based on the same idea, some embodiments of this application also provide the corresponding device and non-volatile computer storage medium for the above method.
[0041] Figure 2 It is a schematic structural diagram of a screen adaptation implementation device for a terminal device provided by an embodiment of this application. As Figure 2 shown, it includes: At least one processor; and, A memory communicatively connected to at least one processor; wherein, The memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor to enable at least one processor to: Execute a screen adaptation implementation method for a terminal device as described in any one of the above.
[0042] An embodiment of this application provides a non-volatile computer storage medium, storing computer-executable instructions, and the computer-executable instructions are set as: A method for implementing screen adaptation of a terminal device as described in any of the above.
[0043] Each embodiment in this application is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. The key point of each embodiment is to illustrate the differences from other embodiments. In particular, for the device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple. For the relevant parts, reference can be made to the partial description of the method embodiments.
[0044] The devices and media provided in the embodiments of this application correspond one by one to the methods. Therefore, the devices and media also have beneficial technical effects similar to those of their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be elaborated here.
[0045] Those skilled in the art should understand that the embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.
[0046] This application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of this application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the flows and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the specified functions in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0047] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the specified functions in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0048] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 steps of the functions specified in one block or multiple blocks.
[0049] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0050] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0051] Computer-readable media includes permanent and non-permanent, removable and non-removable media and can be implemented by any method or technology for information storage. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0052] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising one..." does not exclude the existence of additional identical elements in the process, method, commodity or device comprising the element.
[0053] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A method for implementing screen adaptation of a terminal device, characterized in that The method includes: Determine the application component information to be loaded into the terminal device; wherein, the application component information includes the component size of the application component, and the component size is defined according to density-independent pixels; Determine the target screen parameters corresponding to the terminal device, and load the target layout file corresponding to the application component according to the target screen parameters; Determine the position attribute of the application component according to the layout dependency relationship set in the target layout file; Based on the position attribute and the component size, display the application component on the screen of the terminal device to achieve the adaptation of the application component among terminal devices with different screen parameters.
2. The method for realizing screen adaptation of a terminal device according to claim 1, wherein Before loading the target layout file corresponding to the application component according to the target screen parameters, the method further includes: For terminal devices with different screen parameters, determine the layout dependency relationship corresponding to the terminal device; wherein, the layout dependency relationship is a relative layout dependency or a constraint layout dependency; Construct the layout file corresponding to the terminal device according to the layout dependency relationship.
3. The method for implementing screen adaptation of a terminal device according to claim 2, wherein Constructing the layout file corresponding to the terminal device according to the layout dependency relationship specifically includes: Construct the layout file corresponding to the terminal device according to the layout dependency relationship; In the configuration file corresponding to the layout item of the terminal device, add a dependency on the percentage layout library, and set the layout attribute in the layout file to a percentage layout attribute, so as to layout the application component according to the screen ratio through the percentage layout attribute.
4. A method for realizing screen adaptation of a terminal device according to claim 3, characterized in that, After constructing the layout file corresponding to the terminal device according to the layout dependency relationship, the method further includes: Obtain screen parameters from a preset screen information database; wherein, the screen parameters include resolution; Cluster the different terminal devices corresponding to the screen parameters according to the resolution to divide the terminal devices into several device categories; Under the resource directory of the layout item, create resource folders corresponding to different device categories according to the layout file.
5. The method for realizing screen adaptation of a terminal device according to claim 4, characterized in that, Loading the target layout file corresponding to the application component according to the target screen parameters specifically includes: Determine the target device category to which the terminal device belongs according to the target screen parameters; According to the reference path of the resource folder, obtain the target layout file corresponding to the target device category from the resource directory, and load the target layout file corresponding to the application component.
6. The method for realizing screen adaptation of a terminal device according to claim 1, wherein Determining the position attribute of the application component according to the layout dependency relationship set in the target layout file specifically includes: Determine the layout dependency relationship set in the target layout file; In the case where the layout dependency relationship is a relative layout dependency, determine the position attribute of the application component according to the relative positions between the application components; In the case where the layout dependency relationship is a constraint layout dependency, determine the position attribute of the application component according to the constraint relationships between the application components.
7. A method for realizing screen adaptation of a terminal device according to claim 1, characterized in that, Displaying the application component on the screen of the terminal device based on the position attribute and the component size specifically includes: Detect the screen folding state of the terminal device through a sensor provided in the terminal device; Determine the visible area of the terminal device according to the screen folding state; Based on the position attribute and the component size, display the application component in the visible area.
8. The method for realizing screen adaptation of a terminal device according to claim 4, wherein Before obtaining the screen parameters from the preset screen information database, the method further includes: Collect screen parameters corresponding to terminal devices of different device models from a preset device data source at a preset collection interval; Construct a screen information database according to the screen parameters.
9. An apparatus for realizing screen adaptation of a terminal device, characterized in that The device includes: At least one processor; And a memory communicatively connected to the at least one processor; Wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a method for realizing screen adaptation of a terminal device according to any one of claims 1-8.
10. A non - volatile computer storage medium stores computer - executable instructions, characterized in that, The computer-executable instructions are set to: A method for realizing screen adaptation of a terminal device according to any one of claims 1-8.
Citation Information
Patent Citations
Terminal system interface display method and apparatus
CN105094774A
Percentage-based Android mobile phone screen adaption method
CN105827833A
Full-screen adapting method of display device, display device and storage medium
CN108427546A
Android device screen adaptation method, related device and readable storage medium
CN111443974A
Screen adaptation method and device for vehicle-mounted application, electronic equipment and storage medium
CN114489909A