Dynamic view generation method and system, readable medium and electronic equipment
Through the method of dynamically generating and adjusting UI elements, the problem of limited performance and flexibility when traditional Android applications are dynamically updated, the dynamic expansion and customization of the UI interface are achieved, and the performance and response speed of the application are improved.
Patent Information
- Application Number
- CN202510041071.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-05-16
AI Technical Summary
Traditional Android applications have limited performance and flexibility when dynamically updating views, and cannot meet user input or changes in internal state of the application.
By defining the UI elements that need to be generated dynamically and encapsulated into a Formltem object, dynamically generate the view, and adjust the size, position, color and content of the view at runtime, and finally add the adjusted view to the parent layout.
It realizes dynamic expansion and customization of the UI interface, improves application performance and responsiveness, and enhances flexibility and interactivity.
Smart Images

Figure CN120010842A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a dynamic view generation method, system, readable medium and electronic device, belonging to the technical field of dynamic views. Background Art
[0002] In Android applications, you usually need to use Extensible Markup Language XML layout and style files to create views. This traditional approach requires developers to predict which layouts and styles will apply to all aspects of the application early in the design of the application. However, when the application is running, you may need to dynamically update the view based on user input or the internal state of the application. Traditional methods usually cannot meet this demand because they cannot predict all the layouts and styles generated at runtime. This leads to limited performance and flexibility of the application.
[0003] In current Android applications, the design and development of user interfaces are becoming increasingly complex. The traditional UI design method is to define and describe UI elements through XML layout files, and then dynamically load UI elements according to the layout files to display them to users. However, using XML layout files as a UI design method has certain defects, such as being static, fixed, and inflexible, and cannot meet dynamic and customizable requirements. Summary of the invention
[0004] In view of the above problems, the purpose of the present invention is to provide a dynamic view generation method, system, readable medium and electronic device, which can dynamically generate UI elements and realize dynamic expansion and customizability of UI interface, thereby improving the flexibility and interactivity of UI design and development.
[0005] To achieve the above-mentioned purpose, the present invention proposes the following technical scheme: a dynamic view generation method, comprising the following steps: defining UI elements that need to be dynamically generated, and encapsulating the UI elements as Formltem objects; forming a dynamically generated view according to the Formltem objects; adjusting the dynamically generated view; adding the adjusted view to a parent layout that accommodates the dynamic view, and adding the adjusted view as a child view to the parent view in the parent layout, thereby dynamically generating a new view.
[0006] Furthermore, the Formltem object includes the name, type and attributes of the UI element.
[0007] Furthermore, the dynamically generated view includes a text box, a drop-down list and a picture box.
[0008] Furthermore, the method for dynamically generating a view based on the Formltem object is: loading an XML layout file and creating a view object at runtime; setting layout parameters of the view at runtime; setting the background color or background image of the view at runtime; setting radio buttons or multiple-choice buttons for the view; and setting click events of the view at runtime.
[0009] Furthermore, adjusting the dynamically generated view includes adjusting the size, position, color and content of the dynamically generated view through Java.
[0010] Furthermore, the parent layout is defined by Activity, Fragment, LinearLayout or ViewGroup.
[0011] Furthermore, the dynamic view is added to the parent layout by calling the addView() method of the parent layout. When the added view is no longer used, the view is removed by calling the removeView() method of the parent layout.
[0012] The present invention also discloses a dynamic view generation system, including: a UI element generation module, used to define UI elements that need to be dynamically generated, and encapsulate the UI elements as Formltem objects; a dynamic view generation module, used to form a dynamically generated view according to the Formltem objects; a view adjustment module, used to adjust the dynamically generated view; a view adding module, used to add the adjusted view to a parent layout that accommodates the dynamic view, and add the adjusted view as a child view to the parent view in the parent layout, thereby dynamically generating a new view.
[0013] The present invention further discloses a computer-readable storage medium, on which a computer program is stored. The computer program is executed by a processor to implement any of the above-mentioned dynamic view generation methods.
[0014] The present invention also provides an electronic device, comprising: one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are used to execute any of the dynamic view generation methods described above.
[0015] The technical solution of the present invention has at least the following technical effects or advantages:
[0016] 1. Compared with the prior art, the dynamic view method of the present invention can generate layouts and styles according to runtime conditions, thereby reducing the number of pre-created layouts and styles. This can improve the performance and response speed of the application.
[0017] 2. Improve the flexibility of the application: Using the dynamic view method, users can generate different views based on runtime conditions. This makes the application more flexible and customizable. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of a dynamic view generation method in one embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is described in detail through specific embodiments. However, it should be understood that the provision of specific embodiments is only for a better understanding of the present invention, and they should not be understood as limitations of the present invention. In the description of the present invention, it should be understood that the terms used are only for the purpose of description and cannot be understood as indicating or implying relative importance.
[0020] In order to solve the defects of the prior art that the use of XML layout files as a UI design method has the advantages of being static, fixed, inflexible, and unable to meet the requirements of dynamism and customizability, the present invention proposes a dynamic view generation method, system, readable medium, and electronic device, which can dynamically generate UI elements and realize the dynamic expansion and customizability of the UI interface, thereby improving the flexibility and interactivity of UI design and development. In order to meet the requirements of dynamic expansion and customizability of the UI interface, Dynamic Views technology is widely used. Dynamic Views technology can dynamically create and process views when the application is running, and can dynamically set its size, position, color, content and other attributes according to the needs of the application, thereby realizing the dynamic expansion and customizability of the UI interface. The scheme of the present invention is described in detail below through embodiments in conjunction with the accompanying drawings.
[0021] Embodiment 1
[0022] This embodiment discloses a dynamic view generation method, such as Figure 1 As shown, the following steps are included:
[0023] S1 defines the UI elements that need to be dynamically generated and encapsulates the UI elements as Formltem objects.
[0024] A view binding library can contain one or more XML layout and style files, or it can generate layouts and styles dynamically. A view binding library contains all the layouts and styles for an application.
[0025] According to the application requirements, define the UI elements that need to be dynamically generated and encapsulate the UI elements as FormItem objects. The FormItem object includes information such as the name, type, and attributes of the UI element.
[0026] S2 dynamically generates views based on the Formltem object.
[0027] In the Java code of Activityy or Fragment, the corresponding view is dynamically generated according to the FormItem object. View types include text boxes, drop-down lists, and picture boxes.
[0028] Dynamic view technology can dynamically generate layout and style according to runtime conditions, thereby improving the performance and flexibility of the application. According to dynamic view technology, different views can be dynamically generated at runtime. The method of dynamically generating views based on Formltem objects is:
[0029] LayoutInflater.inflate() method, which loads the XML layout file and creates a view object at runtime;
[0030] View.setLayoutParams() method, which sets the layout parameters of the view at runtime;
[0031] View.setBackgroundResource() method, which sets the background color or background image of the view at runtime;
[0032] View.setOnCheckedChangeListener() method, set radio button or multiple-select button for the view;
[0033] View.setOnClickListener() method sets the view's click event at runtime.
[0034] S3 adjusts dynamically generated views.
[0035] Adjusting the dynamically generated view means adjusting the size, position, color and content of the dynamically generated view through Java.
[0036] S4 adds the adjusted view to the parent layout that accommodates the dynamic view, and adds the adjusted view as a child view to the parent view in the parent layout, thereby dynamically generating a new view.
[0037] The parent layout is defined in the layout file through Activity, Fragment, LinearLayout or ViewGroup to accommodate dynamic views. Use the addView() method in the ViewGroup class to add the adjusted view as a child view to the parent view in the parent layout.
[0038] The dynamic view is added to the parent layout by calling the addView() method of the parent layout. When the added view is no longer used, the view is removed by calling the removeView() method of the parent layout. The view binding library and dynamic view technology are mainly used to generate the interface part of the application. The behavior and logic of the application can be defined in the Java code of the application. The Java code of the application can be used to process user input, perform logical operations, update data models, handle exceptions, etc.
[0039] Through the above steps, this embodiment implements a dynamic view generation method based on Dynamic Views technology, which can dynamically generate UI elements and realize dynamic expansion and customizability of UI interface, thereby improving the flexibility and interactivity of UI design and development.
[0040] Embodiment 2
[0041] Based on the same inventive concept, this embodiment discloses a dynamic view generation system, including:
[0042] The UI element generation module is used to define the UI elements that need to be dynamically generated and encapsulate the UI elements as Formltem objects;
[0043] Dynamically generated view module, used to form dynamically generated views according to Formltem objects;
[0044] A view adjustment module, used to adjust the dynamically generated view;
[0045] The view adding module is used to add the adjusted view to the parent layout that accommodates the dynamic view, and add the adjusted view as a child view to the parent view in the parent layout, so as to dynamically generate a new view.
[0046] Embodiment 3
[0047] Based on the same inventive concept, this embodiment discloses a computer-readable storage medium, on which a computer program is stored. The computer program is executed by a processor to implement any of the above-mentioned dynamic view generation methods.
[0048] Embodiment 4
[0049] Based on the same inventive concept, this embodiment provides an electronic device, comprising: one or more processors; a memory; one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are used to execute any of the above-mentioned dynamic view generation methods.
[0050] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0051] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0052] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0053] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0054] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation of the present invention can still be modified or replaced by equivalents, and any modification or equivalent replacement that does not deviate from the spirit and scope of the present invention should be included in the protection scope of the claims of the present invention. The above content is only a specific implementation of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A dynamic view generation method, characterized in that: The following steps are involved: Define the UI elements that need to be dynamically generated and encapsulate the UI elements as Formltem objects; A dynamically generated view is formed according to the Formltem object; Adjusting the dynamically generated view; Add the adjusted view to the parent layout that holds the dynamic view, and add the adjusted view as a subview to the parent view in the parent layout, thereby dynamically generating a new view.
2. The dynamic view generation method according to claim 1, characterized in that: The Formltem object includes the name, type and attributes of the UI element.
3. The dynamic view generation method according to claim 1, characterized in that: The dynamically generated view includes a text box, a drop-down list and a picture box.
4. The dynamic view generation method according to any one of claims 1 to 3, characterized in that: The method for forming a dynamically generated view according to the Formltem object is: Load XML layout files and create view objects at runtime; Set the layout parameters of the view at runtime; Set the background color or background image of a view at runtime; Set radio buttons or multiple check buttons for the view; Set the click event of the view at runtime.
5. The dynamic view generation method according to claim 1, characterized in that: Adjusting the dynamically generated view is adjusting the size, position, color and content of the dynamically generated view through Java.
6. The dynamic view generation method according to claim 1, characterized in that: The parent layout is defined by Activity, Fragment, LinearLayout or ViewGroup.
7. The dynamic view generation method according to claim 1 or 6, characterized in that: The dynamic view is added to the parent layout by calling the addView() method of the parent layout. When the added view is no longer used, the view is removed by calling the removeView() method of the parent layout.
8. A dynamic view generation system, characterized in that: include: A UI element generation module, used to define UI elements that need to be dynamically generated and encapsulate the UI elements as Formltem objects; A dynamically generated view module, used for forming a dynamically generated view according to the Formltem object; A view adjustment module, used for adjusting the dynamically generated view; The view adding module is used to add the adjusted view to the parent layout that accommodates the dynamic view, and add the adjusted view as a child view to the parent view in the parent layout, so as to dynamically generate a new view.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the dynamic view generation method according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: one or more processors; Memory; One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are used to execute the dynamic view generation method according to any one of claims 1 to 7.