CN111782212A - View assembly creating method and device and storage medium - Google Patents

View assembly creating method and device and storage medium Download PDF

Info

Publication number
CN111782212A
CN111782212A CN202010613257.XA CN202010613257A CN111782212A CN 111782212 A CN111782212 A CN 111782212A CN 202010613257 A CN202010613257 A CN 202010613257A CN 111782212 A CN111782212 A CN 111782212A
Authority
CN
China
Prior art keywords
target
creating
instance
class name
view component
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010613257.XA
Other languages
Chinese (zh)
Inventor
吴伟江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Music Entertainment Technology Shenzhen Co Ltd
Original Assignee
Tencent Music Entertainment Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Music Entertainment Technology Shenzhen Co Ltd filed Critical Tencent Music Entertainment Technology Shenzhen Co Ltd
Priority to CN202010613257.XA priority Critical patent/CN111782212A/en
Publication of CN111782212A publication Critical patent/CN111782212A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/80Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
    • G06F16/84Mapping; Conversion
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons

Abstract

The embodiment of the application discloses a method, a device and a storage medium for creating a view component, wherein a target extensible markup language layout file is acquired when an interface rendering instruction is received; analyzing a target extensible markup language layout file to obtain a target class name of a target view component for interface layout; determining a target instance creation mode corresponding to a target class name in predefined instance creation modes; and creating an instance corresponding to the target class name by using a target instance creating mode. Therefore, the target class name of the target view component for interface layout in the target extensible markup language layout file is determined, the target instance creation mode corresponding to the target class name is determined in a predefined instance creation mode, and the instance corresponding to the target class name is created by using the target instance creation mode, so that subsequent reflection processing is not needed, the time for creating the view component is saved, and the efficiency for creating the view component is greatly improved.

Description

View assembly creating method and device and storage medium
Technical Field
The present application relates to the field of information technology, and in particular, to a method and an apparatus for creating a view component, and a storage medium.
Background
With the continuous development of information technology, users can use application programs to browse a large amount of data, such as text data, image data, audio data, card information, and the like, and Extensible Markup Language (XML) provides a format for describing structural data for the most common tool for data transmission among various application programs, thereby simplifying data exchange and representation in a network.
In the related art, when an application generates a view component (view) by rendering for the first time, an XML layout file needs to be parsed to obtain a class name of each view component, and then reflection is performed through the class name of the view component to create a corresponding instance return.
Disclosure of Invention
The embodiment of the application provides a method and a device for creating a view component and a storage medium, which can improve the efficiency of creating the view component.
In order to solve the above technical problem, an embodiment of the present application provides the following technical solutions:
a method for creating a view component is applied to an android client, and comprises the following steps:
when an interface rendering instruction is received, acquiring a target extensible markup language layout file;
analyzing the target extensible markup language layout file to obtain a target class name of a target view component for interface layout;
determining a target instance creating mode corresponding to the target class name in a predefined instance creating mode, wherein the instance creating mode is not a mode of creating an instance through a reflection process;
and creating an instance corresponding to the target class name by using the target instance creation mode, wherein the instance is used for representing the target view component.
Correspondingly, an embodiment of the present application further provides an apparatus for creating a view component, including:
the method comprises the steps that when an interface rendering instruction is received, an acquisition unit acquires a target extensible markup language layout file;
the analysis unit is used for analyzing the target extensible markup language layout file to obtain a target class name of a target view component for interface layout;
the determining unit is used for determining a target instance creating mode corresponding to the target class name in predefined instance creating modes, wherein the instance creating mode is not a mode of creating an instance through a reflection process;
and the creating unit is used for creating an instance corresponding to the target class name by using the target instance creating mode, and the instance is used for representing the target view component.
Accordingly, embodiments of the present application further provide a storage medium having a computer program stored thereon, where the computer program is executed on a computer, so that the computer executes the method for creating a view component as provided in any of the embodiments of the present application.
According to the method and the device, when an interface rendering instruction is received, a target extensible markup language layout file is obtained; analyzing a target extensible markup language layout file to obtain a target class name of a target view component for interface layout; determining a target instance creation mode corresponding to a target class name in predefined instance creation modes; and creating an instance corresponding to the target class name by using a target instance creating mode. Therefore, the target class name of the target view component for interface layout in the target extensible markup language layout file is determined, the target instance creation mode corresponding to the target class name is determined in a predefined instance creation mode, and the instance corresponding to the target class name is created by using the target instance creation mode, so that subsequent reflection processing is not needed, the time for creating the view component is saved, and the efficiency for creating the view component is greatly improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flow chart diagram of a method for creating a view component according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a scenario of a creating method of a view component according to an embodiment of the present application;
FIG. 3 is another flow chart diagram of a method for creating a view component according to an embodiment of the present application;
FIG. 4 is a schematic diagram of another scenario of a creating method of a view component according to an embodiment of the present application;
FIG. 5 is a schematic structural diagram of a creating apparatus for a view component provided in an embodiment of the present application;
FIG. 6 is another schematic structural diagram of a creating apparatus of a view component provided in an embodiment of the present application;
fig. 7 is a schematic structural diagram of a terminal according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The following are detailed below. The numbers in the following examples are not intended to limit the order of preference of the examples.
The first embodiment,
In this embodiment, the view component creating apparatus will be described from the perspective of the view component creating apparatus, which may be specifically integrated in a network device having a storage unit and installed with a microprocessor and having an arithmetic capability, where the network device may be a terminal or a server, and the terminal is taken as an example for description below.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for creating a view component according to an embodiment of the present application. The method for creating the view component comprises the following steps:
in step 101, when an interface rendering instruction is received, a target extensible markup language layout file is obtained.
The XML layout file is a file scheme which can realize the creation of User Interface (UI) elements of a view component in an operating system and is written and realized through the XML, so that when an Interface rendering instruction is received, for example, a shopping Interface of an application and the like are generated, the XML layout file is obtained, the User Interface is designed in the XML layout file, the appearance of the application can be better isolated from codes for controlling the application behaviors, and the Interface layout is only required to be modified and recompiled every time the source codes are modified or adjusted.
In step 102, the target extensible markup language layout file is parsed to obtain a target class name of the target view component for interface layout.
All XML layout files in an application can be scanned through an automatic script to obtain the corresponding target class names of all view components in the application, wherein the view components are display components in a user interface forming the application, such as a text view component (TextView), an image view component (ImageView) and the like.
In step 103, a target instance creation mode corresponding to the target class name is determined among predefined instance creation modes.
It should be noted that, for better explaining the embodiment of the present application, please refer to fig. 2 together, when creating a view component (CreatView), that is, when an operating system needs to create a view component on a page, an XML layout file needs to be read and parsed, a class name of the view component is taken, the class name of the view component is called back to the factary 2 interface, when a factary 2 interface is set in the operating system, and an instance and a return instance can be normally created through the factary 2 interface, then the operating system can be directly used. But when the factory2 interface is not set, the operating system will continue to find the hash table of sConstanteMap, look up whether there is a constructor corresponding to the class name of the view component, create an instance using the constructor if there is a constructor, and return the instance. But when no constructor is found the operating system will eventually reflect off of the class loader (classloader), creating an instance and returning an instance from the view component. When the view component is created for the first time, there is no corresponding cache data, so that reflection is certainly performed through the class loader, and since a reflection creation process wastes resources of an operating system greatly, a reflection creation time is very long, and thus creation efficiency of the view component is poor, the method in the embodiment of the present application can solve the above problem, specifically referring to the following steps:
the reason why the view component is reflected by the class loader is that the operating system does not have a cache corresponding to the view component, that is, does not have an instance creation mode corresponding to the target class name, so that the target class name of the view component can be defined in the instance creation mode in advance, and the instance creation mode corresponding to the target class name can be determined by directly using the predefined instance creation mode in the later period without reflection by the class loader, thereby avoiding the step of reflection creation.
In some embodiments, the step of determining, in the predefined instance creation manners, a target instance creation manner corresponding to the target class name may include:
(1) in the constructor cached in advance, the object constructor corresponding to the object class name is determined
In an embodiment, the attribute data may be a necessary attribute code for generating the view component, such as width and height data of the view component, so as to facilitate subsequent preloading and increase loading speed, and the attribute data may only be width and height data for generating the view component.
Further, the view component and the attribute data in the preset XML file may be asynchronously created through a preset tool class, for example, an async layout infilter tool, which is a tool class provided by google officers, and is used for asynchronously creating the view component, but rendering and screen-up are not performed, so that a burden of operating system resources is not caused, and since only the necessary attribute data is created, resources of an operating system may be better saved, and preloading of the view component is simultaneously achieved, so that a target class name of the view component is directly cached, and subsequently, a target constructor corresponding to the target class name may be directly determined in a pre-cached constructor, and the target class name of the view component may be generated without a reflection flow.
For example, the preset XML file may be created by:
<Framelayout xmlns=“http://schemas.android.com/apk/res/android”android:layout_width=ldp“android:layout_height=“ldp”>
and writing the previously obtained view component 'TextView' into the preset XML file, and performing asynchronous non-rendering creation to realize preloading of the view component.
<Framelayout xmlns=“http://schemas.android.com/apk/res/android”android:layout_width=ldp“android:layout_height=“ldp”>
<TextView
Android:layout_width=“ldp”android:layout_height=“ldp”/>
In some embodiments, the step of preloading the view component to obtain a preloaded view component may include:
(1.1) inheriting an interface of a factory method to obtain a preset factory class;
(1.2) scanning one or more extensible markup language layout files using an automation script to collect class names of view components;
(1.3) writing the corresponding relation between the class name of the view component and an instance creation code for creating the view component into a preset factory class in a hard coding mode according to a preset grammar rule to obtain a self-defined instance creation class;
(1.4) in a predefined instance creation class, determining a target instance creation code corresponding to the target class name, wherein the instance creation class comprises the corresponding relation obtained by a hard coding mode between the class name of one or more groups of view components and the instance creation code
Referring to fig. 2, the interface of the factory method is the interface of the factory2 method, and may be used to create a view component.
Furthermore, all extensible markup language layout files are scanned through the automatic script to obtain the class name of the view component, the corresponding relation between the class name of the view component and the instance creating code of the view component is written into a preset factory class in a hard coding mode according to a preset grammar rule to obtain a self-defined instance creating class, so that the target instance creating code corresponding to the required target class name can be directly determined subsequently based on the predefined instance creating class, reflection is not needed through a class loader, and the step of reflection creating is avoided. In one embodiment, the predetermined syntax rule may be in the form of switchcase.
For example, the class name and instance creation code for the view component may be written to a preset factory method with preset syntax rules by:
Figure BDA0002561286080000061
in step 104, an instance corresponding to the target class name is created using the target instance creation mode.
The target instance creating mode is defined in advance, so that an instance corresponding to a target class name can be created by directly using the target instance creating mode, the instance is used for representing the target view component, reflection is not needed through a subsequent class loader, the step of reflection creation is avoided, and after the instance is created, the instantiated view component is rendered to obtain a corresponding application page.
In some embodiments, the step of creating an instance corresponding to the target class name by using the target instance creation means may include: using the target constructor, an instance corresponding to the target class name is created.
Since the asynchronous non-rendering creation is performed on the class name and the attribute data of the view component in the preset XML file, the class name of the view component is stored in a cache, and the target constructor can be directly used to create an instance corresponding to the target class name, so that the subsequent reflection creation is not required.
In some embodiments, the creating, by using the target instance creating method, an instance corresponding to the target class name may include: and using the target instance creating code to create an instance corresponding to the target class name.
Since the preset factory class is obtained, when the operating system needs to create the instance of the class name of the view component, the new instance and the return instance can be directly created through the preset factory class, and subsequent reflection creation is not needed.
As can be seen from the above, in the embodiment of the present application, when an interface rendering instruction is received, a target extensible markup language layout file is obtained; analyzing a target extensible markup language layout file to obtain a target class name of a target view component for interface layout; determining a target instance creation mode corresponding to a target class name in predefined instance creation modes; and creating an instance corresponding to the target class name by using a target instance creating mode. Therefore, the target class name of the target view component for interface layout in the target extensible markup language layout file is determined, the target instance creation mode corresponding to the target class name is determined in a predefined instance creation mode, and the instance corresponding to the target class name is created by using the target instance creation mode, so that subsequent reflection processing is not needed, the time for creating the view component is saved, and the efficiency for creating the view component is greatly improved.
Example II,
The method described in the first embodiment is further illustrated by way of example.
In this embodiment, the creation apparatus of the view component will be specifically integrated in a server for explanation.
Referring to fig. 3, fig. 3 is another flow chart illustrating a method for creating a view component according to an embodiment of the present application. The method flow can comprise the following steps:
in step 201, when the terminal receives an interface rendering instruction, a target extensible markup language layout file is obtained.
In step 202, the terminal parses the target xml layout file to obtain the target class name of the target view component for interface layout.
In step 203, the terminal annotates the view component in the extensible markup language layout file with an annotation tool.
It should be noted that, referring to fig. 2, in the process of generating the view component from the XML layout file, the XML layout file needs to be read and parsed, which is also time-consuming.
In order to further save the instantiation creation time, the terminal may annotate the extensible markup language layout file to be optimized in advance through an annotation tool, such as apt (annotation Process tool).
In step 204, the terminal converts the annotated view component into code data through a code generation framework, generates a class file, stores a logical relationship between the class file and the class name of the view component, and generates a hash table.
The terminal may convert the layout information in the XML into corresponding java code data (code data) through a code generation framework, such as a java poet framework, to generate a java file (i.e., a class file), store a logical relationship between the class file and the layout information (a class name of the view component), and generate the hash table.
For example, referring to fig. 4, the java poet framework converts the layout information C in the XML into corresponding java code data, so as to generate a class file B, store the logical relationship between the layout information C and the class file, and further generate a hash table a.
In step 205, the terminal determines a class file corresponding to the target class name in a hash table created in advance.
Referring to fig. 4, the terminal may analyze layout information C in the hash table a created in advance to determine a class file B corresponding to the target class name.
In step 206, the terminal executes the class file to obtain an instance corresponding to the target class name.
The terminal can directly execute the class file B through a java compiler, instance creation is carried out on the target class name of the view component, the instantiated view component is rendered to generate a corresponding application page, the class file B is directly executed to instantiate, reflection through a class loader is not needed, and the step of reflection creation is avoided.
In step 207, when the terminal detects an execution abnormality, a prompt message is generated from the target code data of the execution abnormality and displayed.
In the embodiment of the application, disaster recovery logic is introduced, and in a development stage, when a terminal detects that execution is abnormal, abnormal target code data is acquired to generate corresponding prompt information so as to throw out the abnormality and prompt.
As can be seen from the above, in the embodiment of the present application, when an interface rendering instruction is received, a target extensible markup language layout file is obtained; analyzing a target extensible markup language layout file to obtain a target class name of a target view component for interface layout; determining a target instance creation mode corresponding to a target class name in predefined instance creation modes; and creating an instance corresponding to the target class name by using a target instance creating mode. Therefore, the target class name of the target view component for interface layout in the target extensible markup language layout file is determined, the target instance creation mode corresponding to the target class name is determined in a predefined instance creation mode, and the instance corresponding to the target class name is created by using the target instance creation mode, so that subsequent reflection processing is not needed, the time for creating the view component is saved, and the efficiency for creating the view component is greatly improved.
Example III,
In order to better implement the method for creating the view component provided by the embodiment of the present application, the embodiment of the present application further provides a device based on the method for creating the view component. Wherein the meaning of the noun is the same as that in the creating method of the view component, and the detailed implementation details can refer to the description in the method embodiment.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a creating apparatus of a view component according to an embodiment of the present disclosure, where the creating apparatus of the view component may include an obtaining unit 301, an analyzing unit 302, a determining unit 303, a creating unit 304, and the like.
An obtaining unit 301, configured to obtain a target extensible markup language layout file when an interface rendering instruction is received.
The parsing unit 302 is configured to parse the target xml layout file to obtain a target class name of a target view component for interface layout.
The determining unit 303 determines, in predefined instance creation manners, a target instance creation manner corresponding to the target class name, where the instance creation manner is not a manner of creating an instance through a reflection process.
In some embodiments, the determining unit 303 is configured to: and in a predefined instance creation class, determining a target instance creation code corresponding to the target class name, wherein the instance creation class comprises a corresponding relation obtained by hard coding between the class name of one or more groups of view components and the instance creation code.
In some embodiments, the determining unit 303 is further configured to: inheriting an interface of a factory method to obtain a preset factory class; scanning one or more extensible markup language layout files using an automation script to collect class names for view components; writing the corresponding relation between the class name of the view component and an instance creation code for creating the view component into a preset factory class in a hard coding mode according to a preset grammar rule to obtain a self-defined instance creation class; and in a predefined instance creation class, determining a target instance creation code corresponding to the target class name, wherein the instance creation class comprises a corresponding relation obtained by hard coding between the class name of one or more groups of view components and the instance creation code.
In some embodiments, the determining unit 303 is further configured to determine, in the pre-cached constructors, a target constructor corresponding to the target class name.
In some embodiments, the determining unit 303 is further configured to determine, in a pre-created hash table, a class file corresponding to the target class name; the hash table records a corresponding relationship between a class name of the view component and a class file, and the class file is used for creating an instance of the view component.
In some embodiments, the determining unit 303 is further configured to annotate the view component in the xml layout file with an annotation tool; converting the annotated view components into code data through a code generation framework, and generating a class file; storing the logical relationship between the class file and the class name of the view component to generate a hash table; determining a class file corresponding to the target class name in a pre-established hash table; the hash table records a corresponding relationship between a class name of the view component and a class file, and the class file is used for creating an instance of the view component.
A creating unit 304, configured to create an instance corresponding to the target class name by using the target instance creating manner, where the instance is used to represent the target view component.
In some embodiments, the creating unit 304 is configured to create an instance corresponding to the target class name by using the target instance creation code.
In some embodiments, the creating unit 304 is further configured to create an instance corresponding to the target class name using the target constructor.
In some embodiments, the creating unit 304 is further configured to execute the class file to obtain an instance corresponding to the target class name.
In some embodiments, as shown in fig. 6, the creating apparatus of the view component further includes:
and a prompt unit 305 for generating and displaying prompt information from the target code data of the execution abnormality when the execution abnormality is detected.
The specific implementation of each unit can refer to the previous embodiment, and is not described herein again.
As can be seen from the above, in the embodiment of the present application, when the obtaining unit 301 receives the interface rendering instruction, the target xml layout file is obtained; the parsing unit 302 parses the target xml layout file to obtain a target class name of a target view component for interface layout; the determining unit 303 determines a target instance creation mode corresponding to the target class name in predefined instance creation modes; the creating unit 304 creates an instance corresponding to the target class name using a target instance creating manner. Therefore, the target class name of the target view component for interface layout in the target extensible markup language layout file is determined, the target instance creation mode corresponding to the target class name is determined in a predefined instance creation mode, and the instance corresponding to the target class name is created by using the target instance creation mode, so that subsequent reflection processing is not needed, the time for creating the view component is saved, and the efficiency for creating the view component is greatly improved.
Example four,
The embodiment of the present application further provides a terminal, as shown in fig. 7, which shows a schematic structural diagram of the terminal according to the embodiment of the present application, specifically:
the terminal may include components such as a processor 401 of one or more processing cores, memory 402 of one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that the terminal structure shown in fig. 7 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components. Wherein:
the processor 401 is a control center of the terminal, connects various parts of the entire terminal using various interfaces and lines, and performs various functions of the terminal and processes data by operating or executing software programs and/or modules stored in the memory 402 and calling data stored in the memory 402, thereby performing overall monitoring of the terminal. Optionally, processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 401.
The memory 402 may be used to store software programs and modules, and the processor 401 executes various functional applications and data processing by operating the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 402 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 access to the memory 402.
The terminal further comprises a power supply 403 for supplying power to the various components, and preferably, the power supply 403 is logically connected to the processor 401 through a power management system, so that functions of managing charging, discharging, and power consumption are realized through the power management system. The power supply 403 may also include any component of one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, and the like.
The terminal may further include an input unit 404, and the input unit 404 may be used to receive input numeric or character information and generate a keyboard, mouse, joystick, optical or trackball signal input in relation to user settings and function control.
Although not shown, the terminal may further include a display unit and the like, which will not be described in detail herein. Specifically, in this embodiment, the processor 401 in the terminal loads the executable file corresponding to the process of one or more application programs into the memory 402 according to the following instructions, and the processor 401 runs the application programs stored in the memory 402, thereby implementing various functions as follows:
when an interface rendering instruction is received, acquiring a target extensible markup language layout file;
analyzing the target extensible markup language layout file to obtain a target class name of a target view component for interface layout;
determining a target instance creating mode corresponding to the target class name in a predefined instance creating mode, wherein the instance creating mode is not a mode of creating an instance through a reflection process;
and creating an instance corresponding to the target class name by using the target instance creating mode, wherein the instance is used for representing the target view component.
In the above embodiments, the descriptions of the embodiments have respective emphasis, and parts that are not described in detail in a certain embodiment may refer to the above detailed description of the method for creating a view component, and are not described herein again.
As can be seen from the above, the terminal according to the embodiment of the present application may obtain the target xml layout file when receiving the interface rendering instruction; analyzing a target extensible markup language layout file to obtain a target class name of a target view component for interface layout; determining a target instance creation mode corresponding to a target class name in predefined instance creation modes; and creating an instance corresponding to the target class name by using a target instance creating mode. Therefore, the target class name of the target view component for interface layout in the target extensible markup language layout file is determined, the target instance creation mode corresponding to the target class name is determined in a predefined instance creation mode, and the instance corresponding to the target class name is created by using the target instance creation mode, so that subsequent reflection processing is not needed, the time for creating the view component is saved, and the efficiency for creating the view component is greatly improved.
Example V,
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor.
To this end, the present application provides a storage medium, in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any one of the methods for creating a view component provided in the present application. For example, the instructions may perform the steps of:
when an interface rendering instruction is received, acquiring a target extensible markup language layout file;
analyzing the target extensible markup language layout file to obtain a target class name of a target view component for interface layout;
determining a target instance creating mode corresponding to the target class name in a predefined instance creating mode, wherein the instance creating mode is not a mode of creating an instance through a reflection process;
and creating an instance corresponding to the target class name by using the target instance creating mode, wherein the instance is used for representing the target view component.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
Wherein the storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the instructions stored in the storage medium may execute the steps in any method for creating a view component provided in the embodiment of the present application, beneficial effects that can be achieved by any method for creating a view component provided in the embodiment of the present application may be achieved, which are detailed in the foregoing embodiments and will not be described again here.
The method, the apparatus, and the storage medium for creating a view component provided in the embodiments of the present application are described in detail above, and a specific example is applied in the present application to explain the principles and implementations of the present application, and the description of the above embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method for creating a view component, which is applied to an android client, is characterized by comprising the following steps:
when an interface rendering instruction is received, acquiring a target extensible markup language layout file;
analyzing the target extensible markup language layout file to obtain a target class name of a target view component for interface layout;
determining a target instance creating mode corresponding to the target class name in a predefined instance creating mode, wherein the instance creating mode is not a mode of creating an instance through a reflection process;
and creating an instance corresponding to the target class name by using the target instance creation mode, wherein the instance is used for representing the target view component.
2. The creating method according to claim 1, wherein the step of determining the target instance creating manner corresponding to the target class name among predefined instance creating manners includes:
determining a target instance creating code corresponding to the target class name in a predefined instance creating class, wherein the instance creating class comprises a corresponding relation obtained by hard coding between the class name of one or more groups of view components and the instance creating code;
the step of creating the instance corresponding to the target class name by using the target instance creation mode comprises the following steps:
and using the target instance creating code to create an instance corresponding to the target class name.
3. The method of creating according to claim 2, wherein the step of defining the instance creation class comprises:
inheriting an interface of a factory method to obtain a preset factory class;
scanning one or more extensible markup language layout files using an automation script to collect class names for view components;
and writing the corresponding relation between the class name of the view component and the instance creation code for creating the view component into a preset factory class in a hard coding mode according to a preset grammar rule so as to obtain a self-defined instance creation class.
4. The creating method according to claim 1, wherein the step of determining the target instance creating manner corresponding to the target class name among predefined instance creating manners includes:
determining a target constructor corresponding to the target class name in a constructor cached in advance;
the step of creating the instance corresponding to the target class name by using the target instance creation mode comprises the following steps:
using the target constructor, an instance corresponding to the target class name is created.
5. The creating method according to claim 1, wherein the step of determining the target instance creating manner corresponding to the target class name among predefined instance creating manners includes:
determining a class file corresponding to the target class name in a pre-established hash table; wherein, the hash table records the corresponding relationship between the class name of the view component and the class file, and the class file is used for creating the instance of the view component;
the step of creating the instance corresponding to the target class name by using the target instance creation mode comprises the following steps:
and executing the class file to obtain an example corresponding to the target class name.
6. The creating method according to claim 5, wherein the creating manner of the hash table includes:
annotating view components in the extensible markup language layout file with an annotation tool;
converting the annotated view components into code data through a code generation framework, and generating a class file;
and storing the logical relationship between the class file and the class name of the view component to generate a hash table.
7. The creation method according to any one of claims 1 to 6, characterized by further comprising:
and when the execution abnormity is detected, generating prompt information according to the target code data of the execution abnormity and displaying the prompt information.
8. An apparatus for creating a view component, comprising:
the system comprises an acquisition unit, a display unit and a display unit, wherein the acquisition unit is used for acquiring a target extensible markup language layout file when an interface rendering instruction is received;
the analysis unit is used for analyzing the target extensible markup language layout file to obtain a target class name of a target view component for interface layout;
the determining unit is used for determining a target instance creating mode corresponding to the target class name in a predefined instance creating mode, wherein the instance creating mode is not a mode of creating an instance through a reflection process;
and the creating unit is used for creating an instance corresponding to the target class name by using the target instance creating mode, and the instance is used for representing the target view component.
9. The apparatus for creating a view component according to claim 8, wherein the determining unit is configured to:
determining a target instance creating code corresponding to the target class name in a predefined instance creating class, wherein the instance creating class comprises a corresponding relation obtained by hard coding between the class name of one or more groups of view components and the instance creating code;
the creating unit is configured to:
and using the target instance creating code to create an instance corresponding to the target class name.
10. A storage medium having stored thereon a computer program, characterized in that, when the computer program is run on a computer, it causes the computer to execute the method of creating a view component according to any one of claims 1 to 7.
CN202010613257.XA 2020-06-30 2020-06-30 View assembly creating method and device and storage medium Pending CN111782212A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010613257.XA CN111782212A (en) 2020-06-30 2020-06-30 View assembly creating method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010613257.XA CN111782212A (en) 2020-06-30 2020-06-30 View assembly creating method and device and storage medium

Publications (1)

Publication Number Publication Date
CN111782212A true CN111782212A (en) 2020-10-16

Family

ID=72761257

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010613257.XA Pending CN111782212A (en) 2020-06-30 2020-06-30 View assembly creating method and device and storage medium

Country Status (1)

Country Link
CN (1) CN111782212A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463272A (en) * 2020-11-13 2021-03-09 广州市百果园网络科技有限公司 Interface layout loading display method and system, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463272A (en) * 2020-11-13 2021-03-09 广州市百果园网络科技有限公司 Interface layout loading display method and system, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US20100281463A1 (en) XML based scripting framework, and methods of providing automated interactions with remote systems
US8201143B2 (en) Dynamic mating of a modified user interface with pre-modified user interface code library
US8650532B2 (en) Change notification and information update based on uncompiled software development project
CN110673847A (en) Configuration page generation method and device, electronic equipment and readable storage medium
US8082494B2 (en) Rendering markup language macro data for display in a graphical user interface
US20230229406A1 (en) Page rendering method, apparatus, electronic device, computer-readable storage medium, and computer program product
CN102298518B (en) Conversion from the administration order of technology the unknown to multiple management agreement
US9141344B2 (en) Hover help support for application source code
US20140258371A1 (en) Collaborative editing
CN112506854A (en) Method, device, equipment and medium for storing page template file and generating page
CN113971037A (en) Application processing method and device, electronic equipment and storage medium
US20140282123A1 (en) Executable guidance experiences based on implicitly generated guidance models
CN115576974A (en) Data processing method, device, equipment and medium
CN114048415A (en) Form generation method and device, electronic equipment and computer readable storage medium
US8112500B2 (en) Technique of relaying communications between client apparatus and server apparatus
US9274755B2 (en) Infrastructure for generating code using annotation and template generators
CN111782212A (en) View assembly creating method and device and storage medium
US20130145343A1 (en) Workspace model for interrelated projects
CN113268232B (en) Page skin generation method and device and computer readable storage medium
CN110825425A (en) Configuration data management method and device, electronic equipment and storage medium
CN111913741A (en) Object interception method, device, medium and electronic equipment
CN111427568A (en) Interface configuration method and device
CN111126008A (en) XSD-based code generation method and device, computer equipment and storage medium
CN113296759B (en) User interface processing method, user interface processing system, device and storage medium
CN114911541A (en) Configuration information processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination