Application interface layout method and electronic device

IN598222BActive Publication Date: 2026-08-06HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
IN202327020535
Authority / Receiving Office
IN · IN
Patent Type
Patents
Current Assignee / Owner
Priority Date
2020-09-29
Filing Date
2023-03-23
Publication Date
2026-08-06
Estimated Expiration
2041-09-15

AI Technical Summary

Technical Problem

Developers face a heavy workload in designing and maintaining different layout files for various electronic device displays with distinct specifications, leading to inefficient development and increased storage and download costs due to the need for multiple layout files.

Method used

An adaptive application interface layout method that uses a single layout file with preset capabilities such as extension, proportion, equalization, hiding, and stretching capabilities, which adjusts the layout based on device parameters like screen type and status, allowing electronic devices to dynamically change the sizes and locations of child views to accommodate different display requirements.

Benefits of technology

This approach reduces development and maintenance workload, enables consistent display across diverse devices, and optimizes storage and download efficiency by using a single layout file, while ensuring effective display on devices with different screen specifications.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

An application interface layout method and an electronic device, relating to the technical field of electronics, and being capable of reducing the workload of an application developer for developing and maintaining a layout file of an application interface. The method specifically comprises: a developer provides, in a layout file of an application, a layout container having an adaptive layout capability, wherein the adaptive layout capability comprises at least one of an extension capability, a proportion capability, an equal division capability, a wrapping capability, a hiding capability, a stretching capability, or a scaling capability. Thus, when the electronic device runs the application, the sizes and positions of child controls in the layout container on a display interface are laid out according to a screen parameter of the electronic device and the adaptive layout capability of the layout container in the layout file.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0002] This application relates to the field of electronic technologies, and in particular, to anapplication interface layout method and an electronic device.BACKGROUND

[0003] An electronic device provides diversified application functions for a user by using anapplication (referred to as an application below). Generally, when developing an application, adeveloper designs a layout of a view (View) or a view group (ViewGroup) on each displayinterface of the application, to form a layout file, and packs the layout file into an installationpackage of the application. When the electronic device installs and runs the application, acorresponding layout file is invoked, so as to present a corresponding display interface on adisplay. Currently, there is an increasing quantity of categories of electronic devices, and displaysof various specifications (for example, dimensions) appear. If the developer needs to design anddevelop different layout files for the displays of all specifications, development and maintenanceworkload is heavy.SUMMARY

[0004] This application provides an application interface layout method and an electronicdevice, so as to reduce workload of an application developer in developing and maintaining alayout file of an application interface.

[0005] To achieve the foregoing objectives, embodiments of this application provide thefollowing technical solutions.

[0006] According to a first aspect, an application interface layout method is provided. Anelectronic device installs an application installation package of a first application, the applicationinstallation package includes a first layout file, the first layout file indicates N child views and anenabled preset capability, and N is a positive integer. The preset capability includes one or moreof an extension capability, a proportion capability, an equalization capability, a stretchingcapability, and a hiding capability. The method includes: The electronic device receives a firstoperation performed by a user on a first interface. In response to the received first operation, theelectronic device determines attribute values of the N child views based on a device parameter ofthe electronic device and the preset capability, where the device parameter of the electronicdevice includes at least one of a screen type value, a screen dimension value, or a running statusvalue of the electronic device, and the attribute values of the N child views are used to indicatesizes and locations of the N child views on a second interface. The electronic device displays theN child views on the second interface based on the attribute values of the N child views.

[0007] A screen type includes any one of a bezel-less screen, a curved screen, a notch screen,a drop screen, a foldable screen, and the like. It is easy to understand that the screen type affectsan overall display size and display location of the first application on a screen, and further affectsdisplay of a child view in a first layout container. A running status includes one or more of alandscape / portrait state, a screen splitting state, and a folding state of the electronic device. It iseasy to understand that different running statuses of the electronic device indicate differentdisplay sizes and display locations of the first application on the screen, so as to restrict displayof a child view in the first layout container.

[0008] It can be learned that the attribute values of the N child views in the first layout fileare not fixed, but are related to the device parameter of the electronic device. The deviceparameter includes at least one of a screen type, a screen dimension, or a running status of thedevice. In other words, when electronic device parameters are different, the electronic deviceadaptively changes the sizes and / or the locations of the N child views based on the deviceparameters of the electronic device and the preset capability. It can be further learned that thissolution can enable electronic devices having different device parameters to present differentdisplay effects based on a same layout file, reduce development and maintenance workload ofdevelopers, and meet display requirements of various types of electronic devices.

[0009] In addition, compared with a solution in which an application installation packageneeds to carry a plurality of layout files, this solution in which an application installationpackage carries one layout file increases traffic costs and time costs of downloading anapplication installation package by the electronic device. In addition, after installing theapplication, the electronic device does not need to store another redundant layout file. Thisincreases storage space utilization of the electronic device.

[0010] It should be further noted that the foregoing preset capabilities (namely, adaptivelayout capabilities) may be used independently, or may be used in combination with each other.For example, different adaptive layout capability attributes are set for different objects (Views orViewGroups) on a same application interface, or two or more adaptive layout capabilityattributes are set for a same object. It can be understood that, in an actual applicationdevelopment process, in addition to a case in which a conflict occurs during combination, theforegoing adaptive layout capabilities may be randomly combined according to an actualrequirement. For example, the stretching capability may be combined with any one of the hidingcapability, the proportion capability, the equalization capability, and a wrapping capability, and ascaling capability may be combined with any one of the hiding capability, the proportioncapability, the equalization capability, and the wrapping capability.

[0011] In a possible implementation, the first layout file includes a preset parametercorresponding to the preset capability. That the electronic device determines attribute values ofthe N child views based on a device parameter of the electronic device and the preset capabilityincludes: The electronic device determines the attribute values of the N child views based on thedevice parameter of the electronic device, the preset capability, and the preset parameter.

[0012] In a possible implementation, a running status of the electronic device includes one ormore of a landscape / portrait state, a screen splitting state, and a folding state of the electronicdevice.

[0013] In a possible implementation, the first operation is any one of an operation of startingthe first application, an operation of jumping to the second interface, or an operation of switchingthe running status of the electronic device.

[0014] For example, if the second interface is a home page of the first application, the firstoperation is an operation of starting the first application; or if the second interface is not a homepage of the first application, the first operation is an operation of indicating to jump from the firstinterface to the second interface. In another scenario, when the electronic device displays aninterface of the first application, if it is detected that the user switches the running status of theelectronic device, for example, switches from a portrait state to a landscape state, or switchesfrom an expanded state to a folded state, or switches from a non-split-screen state to asplit-screen state, the electronic device re-obtains a device parameter of the device, re-calculatesattribute values of the N child views based on the updated device parameter of the device and thepreset capability, and refreshes the current interface. In other words, a same function interface ofthe first application has different layouts in different running statues of the electronic device, thatis, layouts of the N child views on the second interface and the first interface are different.

[0015] In a possible implementation, the preset capability is the extension capability, the firstlayout file indicates that the N child views are arranged in a first orientation of a first layoutcontainer, and the first orientation is a horizontal orientation or a vertical orientation. That theelectronic device determines attribute values of the N child views based on a device parameter ofthe electronic device and the preset capability includes: The electronic device determines adimension of the first layout container in the first orientation based on the device parameter; anddetermines N1 child views and the (N1+1)th child view in the N child views based on thedimension of the first layout container in the first orientation and dimensions of the N childviews in the first orientation, where N1 is less than N. That the electronic device displays the Nchild views on the second interface based on the attribute values of the N child views includes:The electronic device completely displays the N1 child views and partially displays the (N1+1)thchild view on the second interface based on the attribute values of the N child views.

[0016] In other words, when a width of a layout container changes, a quantity of displayedchild views may be automatically determined based on a dimension of the layout container, so asto meet display requirements of electronic devices having different screen dimensions. Inaddition, in this application, the quantity of displayed child views may be adaptively reducedbased on the change of the layout container, and a child view that displays only partial contentmay also be displayed. A dimension of the partial content displayed by the child view may keepa fixed value (that is, a dimension threshold). In this way, the child view that displays onlypartial content may be used to prompt the user that there is still a child view that is not displayedin the layout container. In addition, keeping the dimension threshold as a fixed value can preventthe user from feeling jagged confusion caused because different screen dimensions lead todifferent dimensions of child views that display partial content.

[0017] In a possible implementation, a preset parameter of the extension capability includesa first dimension and a first spacing. That the electronic device determines attribute values of theN child views based on a device parameter of the electronic device and the preset capabilityincludes: determining, based on the dimension of the first layout container in the first orientation,the dimensions of the N child views in the first orientation, the first dimension, and the firstspacing, that the N1 child views are displayed in the first layout container, and determiningpartial content displayed by the (N1+1)th child view. That the electronic device displays the Nchild views on the second interface based on the attribute values of the N child views includes:The electronic device displays the N1 child views and the partial content of the (N1+1)th childview on the second interface, where a spacing between two adjacent child views is greater thanor equal to the first spacing.

[0018] The first spacing is a spacing threshold. The first dimension is a displayed dimensionof the (N1+1)th child view. In this way, the developer may set a spacing between first child viewsin the first layout container, so as to avoid excessive congestion or content overlapping of thefirst child views.

[0019] In a possible implementation, the preset parameter of the extension capability furtherincludes a second spacing, and the second spacing is greater than the first spacing. Before thedetermining, based on the dimension of the first layout container in the first orientation, thedimensions of the N child views in the first orientation, the first dimension, and the first spacing,that the N1 child views are displayed in the first layout container, and determining partial contentdisplayed by the (N1+1)th child view, the method further includes: determining, based on thedimension of the first layout container in the first orientation, the dimensions of the N childviews in the first orientation, and the second spacing, that the first layout container cannotdisplay all the N child views; narrowing a spacing between two adjacent child views, andkeeping the spacing between two adjacent child views not less than the first spacing; and in aprocess of narrowing the spacing between two adjacent child views, determining that the firstlayout container cannot display all the N child views.

[0020] It can be learned that the developer may set a default spacing between first childviews. When the dimension of the first layout container is insufficient to display all first childviews, the spacing between first child views may be further narrowed to attempt to display all thefirst child views. After the spacing between first child views is narrowed but not all the first childviews can be displayed, a child view that is incompletely displayed may be displayed.

[0021] In a possible implementation, the determining, based on the dimension of the firstlayout container in the first orientation, the dimensions of the N child views in the firstorientation, the first dimension, and the first spacing, that the N1 child views are displayed in thefirst layout container, and determining partial content displayed by the (N1+1)th child viewincludes: determining, based on the dimension of the first layout container in the first orientation,the dimensions of the N child views in the first orientation, the second spacing, and the firstdimension, that N2 child views are displayed in the first layout container, where a spacingbetween two adjacent child views in the N2 child views is a third spacing, N2 is greater than orequal to N1 and is less than N, and a value of N2 is decreased by one if the third spacing is lessthan the first spacing; adjusting the third spacing based on the dimension of the first layoutcontainer in the first orientation, dimensions of the N2 child views in the first orientation, and thefirst dimension; and when an adjusted third spacing is not less than the first spacing, determiningthat the N1 child views are displayed in the first layout container, determining the partial contentdisplayed by the (N1+1)th child view, and determining that a spacing between two adjacent childviews is a fourth spacing, where N1 = N2, and a difference between the fourth spacing and theadjusted third spacing is within one pixel.

[0022] In other words, when the first layout container cannot display all first child views, thequantity N2 of first child views that can be completely displayed may be first determined basedon the default spacing, the dimension of the first layout container, and dimensions of the firstchild views, and then the third spacing between two adjacent first child views is adjusted. If thethird spacing does not meet a spacing threshold, the value of N2 is decreased by one, and thethird spacing is adjusted again. This operation is repeated until the third spacing can meet thespacing threshold. In this case, it is determined that adjusted N2 is the quantity of first childviews that can be completely displayed in the first layout container, and the spacing between firstchild views is determined.

[0023] In addition, because the electronic device performs display in a unit of pixel, aremaining space (the dimension of the first layout container minus an inner margin, a sum of thedimensions of the first child views, or the like) cannot be evenly allocated strictly, that is, thethird spacing may not be an integer. Therefore, spacings between child views may be furtherfine-tuned, so that the spacings between child views completely occupy the remaining space. Adifference between a fine-tuned spacing and the third spacing is within one pixel. For a specificfine-tuning method, refer to related content in this specification.

[0024] In a possible implementation, the method further includes: receiving a secondoperation performed by the user on the second interface; and displaying a third interface inresponse to the second operation, where the third interface displays the (N1+2)th child view.

[0025] Because not all the first child views in the first layout container are displayed on thesecond interface, a first child view that is not displayed on the second interface, for example, the(N1+2)th first child view, may be viewed by performing the second operation.

[0026] In a possible implementation, the preset capability is the proportion capability, thefirst layout file indicates that the N child views are arranged in a first orientation of a first layoutcontainer, the first orientation is a horizontal orientation or a vertical orientation, and a presetparameter corresponding to the proportion capability includes a proportion of a first child viewin the N child views. That the electronic device determines attribute values of the N child viewsbased on a device parameter of the electronic device and the preset capability includes: Theelectronic device determines a dimension of the first layout container in the first orientationbased on the device parameter; and determines a dimension of the first child view in the firstorientation based on the dimension of the first layout container in the first orientation and theproportion of the first child view. That the electronic device displays the N child views on thesecond interface based on the attribute values of the N child views includes: The electronicdevice displays the first child view on the second interface. The first orientation may be a layoutorientation of the first layout container, or may be an orientation specified by the user.

[0027] In other words, when the electronic device runs the application, the electronic deviceobtains the device parameter, determines a display dimension and a display location of theapplication based on the device parameter, and further determines a dimension of the first layoutcontainer and the like. Then, the electronic device calculates a dimension of a child view basedon a specified proportion of the child view and the dimension of the first layout container, so asto meet display requirements of electronic devices having different screen parameters. It can belearned that the hiding capability in this solution can enable electronic devices having differentscreen specifications to present different display effects based on a same layout setting, reducedevelopment and maintenance workload of developers, and meet display requirements of varioustypes of electronic devices.

[0028] In a possible implementation, the preset parameter corresponding to the proportioncapability further includes a proportion of a second child view in the N child views. That theelectronic device determines attribute values of the N child views based on a device parameter ofthe electronic device and the preset capability further includes: determining a dimension of thesecond child view in the first orientation based on the dimension of the first layout container inthe first orientation and the proportion of the second child view, where the proportion of thesecond child view is the same as or different from the proportion of the first child view. That theelectronic device displays the N child views on the second interface based on the attribute valuesof the N child views further includes: The electronic device further displays the second childview on the second interface based on the attribute values of the N child views.

[0029] In other words, different child views in the first layout container may have differentproportions, so as to meet different display requirements.

[0030] In a possible implementation, the preset parameter corresponding to the proportioncapability further includes a case in which no proportion is set for a third child view in the Nchild views, or the preset parameter corresponding to the proportion capability does not include aproportion of the third child view. That the electronic device determines attribute values of the Nchild views based on a device parameter of the electronic device and the preset capability furtherincludes: determining a remaining space of the first layout container in the first orientation,where the remaining space of the first layout container in the first orientation is determined basedon the dimension of the first layout container in the first orientation, an inner margin of the firstlayout container in the first orientation, and a dimension of a child view that is included in thefirst layout container and for which a proportion is set; and determining a dimension of the thirdchild view in the first orientation based on the remaining space of the first layout container in thefirst orientation. That the electronic device displays the N child views on the second interfacebased on the attribute values of the N child views further includes: The electronic device furtherdisplays the third child view on the second interface based on the attribute values of the N childviews.

[0031] It can be learned that the first layout container may include a child view for which aproportion is set, or may include a child view for which no proportion is set. A dimension of thechild view for which a proportion is set may be first determined, and then a dimension of thechild view for which no proportion is set is determined based on the remaining space of the firstlayout container.

[0032] In a possible implementation, the first child view is a layout container view, the firstchild view includes a fourth child view for which a proportion is set, a layout orientation of thefirst child view is a second orientation, and the second orientation is perpendicular to the firstorientation. That the electronic device determines attribute values of the N child views based ona device parameter of the electronic device and the preset capability further includes: Theelectronic device determines a dimension of the first child view in the second orientation basedon the device parameter; and determines a dimension of the fourth child view in the secondorientation based on the dimension of the first child view in the second orientation and theproportion of the fourth child view. That the electronic device displays the N child views on thesecond interface based on the attribute values of the N child views includes: The electronicdevice displays the fourth child view in the first child view.

[0033] In other words, an interface of a layout container with a proportion capability enabledis nested in another layout container with a proportion capability enabled.

[0034] In a specific implementation, a proportion capability may be set for a layout containerin which a text view, a button view, an image view, or the like is located. When a width or aheight of the layout container changes, a width or a height of the text view, the button view, orthe image view may automatically and adaptively change based on the width or the height of thelayout container, so as to meet display requirements of electronic devices having different screendimensions. It can be learned that the proportion capability in this solution can enable electronicdevices having different screen parameters to present different display effects based on a samelayout setting, reduce development and maintenance workload of developers, and meet displayrequirements of various types of electronic devices.

[0035] In a possible implementation, the preset capability is the equalization capability, andthe first layout file indicates that the N child views are arranged in a first orientation of a firstlayout container and indicates a dimension of each of the N child views in the first orientationand an inner margin of the first layout container in the first orientation. That the electronic devicedetermines attribute values of the N child views based on a device parameter of the electronicdevice and the preset capability includes: The electronic device determines a dimension of thefirst layout container in the first orientation based on the device parameter; and determines a firstspacing based on the dimension of the first layout container in the first orientation, the dimensionof each of the N child views in the first orientation, and the inner margin of the first layoutcontainer in the first orientation, where the first spacing is a spacing between two adjacent childviews, and two adjacent child views have an equal spacing. That the electronic device displaysthe N child views on the second interface based on the attribute values of the N child viewsincludes: The electronic device displays the N child views on the second interface based on theattribute values of the N child views, where a spacing between two adjacent child views is thefirst spacing.

[0036] In other words, when the electronic device runs the application, the electronic deviceobtains the device parameter, determines a display dimension and a display location of theapplication based on the device parameter, and further determines a dimension of the first layoutcontainer and the like. Then, the electronic device adaptively determines a spacing betweenadjacent child views based on a width / height of the first layout container, an inner margin of thefirst layout container, and a width / height of each child view in the first layout container. It can belearned that the equalization capability in this solution can enable electronic devices havingdifferent screen specifications to present different display effects based on a same layout setting,reduce development and maintenance workload of developers, and meet display requirements ofvarious types of electronic devices.

[0037] In a possible implementation, a preset parameter of the equalization capabilityincludes a spacing type corresponding to the first layout container, and the spacing type is a firsttype or a second type. After the determining a first spacing, the method further includes:determining a location of the 1st child view in the N child views based on the first orientation andthe spacing type corresponding to the first layout container. When the first orientation is ahorizontal orientation and the first layout container corresponds to the first type, a distancebetween a left edge of the 1st child view and a left edge of the first layout container is 0 or a leftinner margin of the first layout container; when the first orientation is a horizontal orientationand the first layout container corresponds to the second type, a distance between a left edge ofthe 1st child view and a left edge of the first layout container is determined based on a left innermargin of the first layout container and the first spacing; when the first orientation is a verticalorientation and the first layout container corresponds to the first type, a distance between anupper edge of the 1st child view and an upper edge of the first layout container is 0 or an upperinner margin of the first layout container; or when the first orientation is a vertical orientationand the first layout container corresponds to the second type, a distance between an upper edgeof the 1st child view and an upper edge of the first layout container is determined based on anupper inner margin of the first layout container and the first spacing.

[0038] It can be learned that two different types of equalization methods are defined. Theforegoing first-type equalization method means that no spacing needs to be allocated to a sidethat is of the 1st child view and that is closest to a layout container in a layout orientation and aside that is of the last child view and that is closest to the layout container in the layoutorientation. The foregoing second-type equalization capability means that a spacing needs to beallocated to a side that is of the 1st child view and that is closest to a layout container in a layoutorientation and a side that is of the last child view and that is closest to the layout container in thelayout orientation. This meets different spacing adjustment requirements of the user.

[0039] In a possible implementation, the preset parameter of the equalization capabilityfurther includes a first threshold, and the determining a first spacing includes: determining adimension of a first space based on the dimension of the first layout container in the firstorientation, the dimension of each of the N child views in the first orientation, and the innermargin of the first layout container in the first orientation; when the first layout containercorresponds to the first type, evenly dividing the dimension of the first space into N-1 parts,where a dimension of each part is a second spacing; or when the first layout containercorresponds to the second type, evenly dividing the dimension of the first space into N+1 parts,where a dimension of each part is a second spacing; and when the second spacing is greater thanthe first threshold, determining the first threshold as the first spacing; or when the secondspacing is not greater than the first threshold, determining the second spacing as the first spacing.

[0040] It can be learned that the first threshold may be set to restrict a range of an adjustedspacing between child views, so that the adjusted spacing is not greater than the first threshold.

[0041] In a possible implementation, after the determining a location of the 1st child view inthe N child views based on the first orientation and the spacing type corresponding to the firstlayout container, the method further includes: after the first threshold is determined as the firstspacing, adjusting the location of the 1st child view in the first layout container in an alignmentmanner of the N child views in the first layout container, where the alignment manner is any oneof horizontal centering, left alignment, right alignment, vertical centering, top alignment, andbottom alignment.

[0042] In a possible implementation, the preset parameter of the equalization capabilityfurther includes a second threshold, and the determining a first spacing includes: determining adimension of a first space based on the dimension of the first layout container in the firstorientation, the dimension of each of the N child views in the first orientation, and the innermargin of the first layout container in the first orientation; when the first layout containercorresponds to the first type, evenly dividing the dimension of the first space into N-1 parts,where a dimension of each part is a third spacing; or when the first layout container correspondsto the second type, evenly dividing the dimension of the first space into N+1 parts, where adimension of each part is a third spacing; and when the third spacing is less than the secondthreshold, determining the second threshold as the first spacing; or when the third spacing is notless than the second threshold, determining the third spacing as the first spacing.

[0043] It can be learned that the second threshold may be further set to restrict a range of anadjusted spacing between child views, so that the adjusted spacing is not less than the secondthreshold.

[0044] In a possible implementation, the preset capability is the hiding capability, and thefirst layout file indicates that the N child views are arranged in a first orientation of a first layoutcontainer and indicates a dimension of each of the N child views in the first orientation and aninner margin of the first layout container in the first orientation. That the electronic devicedetermines attribute values of the N child views based on a device parameter of the electronicdevice and the preset capability includes: The electronic device determines a dimension of thefirst layout container in the first orientation based on the device parameter; and determines Mchild views from the N child views when a first dimension is greater than a second dimension,where M is an integer less than N, the first dimension is determined based on the dimensions ofthe N child views in the first orientation, and the second dimension is determined based on thedimension of the first layout container in the first orientation and the inner margin of the firstlayout container in the first orientation. That the electronic device displays the N child views onthe second interface based on the attribute values of the N child views includes: The electronicdevice displays the M child views on the second interface based on the attribute values of the Nchild views.

[0045] In other words, when the electronic device runs the application, the electronic deviceobtains the device parameter, determines a display dimension and a display location of theapplication based on the device parameter, and further determines a dimension of the first layoutcontainer and the like. When a width or a height of a layout container is insufficient to display allchild views, some child views in the layout container may be automatically determined to behidden, so as to meet display requirements of electronic devices having different screendimensions. It can be learned that the hiding capability in this solution can enable electronicdevices having different screen specifications to present different display effects based on a samelayout setting, reduce development and maintenance workload of developers, and meet displayrequirements of various types of electronic devices.

[0046] In a possible implementation, a sum of dimensions of the M child views in the firstorientation is less than or equal to the second dimension.

[0047] In the conventional technology, when the electronic device cannot display all childviews in the first layout container, content that exceeds the dimension of the first layoutcontainer is simply truncated. Consequently, some child views display only partial content, and adisplay interface is disordered. However, in the solution provided in this application, the M childviews displayed in the first layout container are child views with complete content, that is, allcontent of the M child views is displayed, and the display interface is displayed neatly.

[0048] In a possible implementation, the determining M child views from the N child viewswhen a first dimension is greater than a second dimension includes: determining the M childviews from the N child views based on priorities of the N child views when the first dimension isgreater than the second dimension.

[0049] In a possible implementation, priorities of the M child views each are lower thanpriorities of the other N-M child views in the N child views.

[0050] In other words, an importance degree of a child view in the first layout container maybe set by setting a priority of the child view. This can avoid a case in which child views arrangedbehind are simply hidden or not displayed when the first layout container cannot display all childviews.

[0051] In a possible implementation, a preset parameter of the hiding capability includes acase in which the N child views include at least one first child view, at least one second childview, and at least one third child view, a priority of the first child view is higher than a priority ofthe second child view, and the priority of the second child view is higher than a priority of thethird child view. The determining the M child views from the N child views based on prioritiesof the N child views when the first dimension is greater than the second dimension includes:when the first dimension is greater than the second dimension, determining that the M childviews do not include the first child view; when a sum of dimensions of the second child viewand the third child view in the first orientation is less than or equal to the second dimension,determining that the M child views include the second child view and the third child view; orwhen a sum of dimensions of the second child view and the third child view in the firstorientation is greater than the second dimension, determining that the M child views do notinclude the first child view and the second child view; and when a sum of the dimensions of thethird child views in the first orientation is less than or equal to the second dimension,determining that the M child views include the third child views.

[0052] In other words, when the first layout container cannot display all child views, hiddenchild views are sequentially determined in descending order of hiding priorities of the childviews.

[0053] In a possible implementation, the preset parameter of the hiding capability furtherincludes a case in which the N child views include at least one first child view, at least onesecond child view, and at least one third child view, a priority of the first child view is higherthan a priority of the second child view, and the priority of the second child view is higher than apriority of the third child view. The determining the M child views based on priorities of the Nchild views when the first dimension is greater than the second dimension includes: determiningthat the M child views include the third child view; and when a sum of dimensions of the thirdchild view and the second child view in the first orientation is less than or equal to the seconddimension, determining that the M child views further include the second child view; or when asum of dimensions of the third child view and the second child view in the first orientation isgreater than the second dimension, determining that the M child views do not include the secondchild view and the first child view.

[0054] In other words, when the first layout container cannot display all child views,displayed child views are sequentially determined in ascending order of hiding priorities of thechild views.

[0055] In a possible implementation, after the determining M child views from the N childviews, the method further includes: determining a spacing between adjacent child views in the Mchild views based on the second dimension and the sum of the dimensions of the M child viewsin the first orientation.

[0056] After a quantity of child views displayed in the layout container is determined, aspacing between adjacent child views is further adjusted, so as to help the layout containerpresent a better display effect.

[0057] In a possible implementation, spacings between adjacent child views in the M childviews are equal or unequal.

[0058] In a possible implementation, the preset capability is the stretching capability, the firstlayout file indicates that the N child views are arranged in a second orientation of a first layoutcontainer, and a preset parameter corresponding to the stretching capability includes a firstthreshold and / or a second threshold of the first layout container in the first orientation, where thesecond orientation is different from the first orientation, and the second threshold is less than thefirst threshold. That the electronic device determines attribute values of the N child views basedon a device parameter of the electronic device and the preset capability includes: The electronicdevice determines an initial value of a dimension of the first layout container in the firstorientation based on the device parameter; if the initial value is greater than the first threshold,determines that the dimension of the first layout container in the first orientation is the firstthreshold; or if the initial value is less than the second threshold, determines that the dimensionof the first layout container in the first orientation is the second threshold; and determines adimension of a first child view in the first layout container in the first orientation based on thedimension of the first layout container in the first orientation, where the first child view is one ofthe N child views. That the electronic device displays the N child views on the second interfacebased on the attribute values of the N child views includes: The electronic device displays thefirst child view on the second interface based on the attribute values of the N child views.

[0059] When the electronic device runs the application, the electronic device obtains thedevice parameter, determines a display dimension and a display location of the application basedon the device parameter, and further determines the initial value of the dimension of the firstlayout container in the first orientation based on a dimension constraint transferred by a parentlayout container of the first layout container, or determines the initial value of the dimension ofthe first layout container in the first orientation based on a dimension that is set in the layout file.The first threshold may be a maximum dimension value that is of the first layout container in thefirst orientation and that is set in the layout file, and the second threshold may be a minimumdimension value that is of the first layout container in the first orientation and that is set in thelayout file.

[0060] It can be learned that, in this application, after the initial value of the dimension of thefirst layout container in the first orientation is determined, the dimension of the first layoutcontainer in the first orientation may be adjusted by using the first threshold and the secondthreshold, so as to avoid excessive scale-up or scale-down of the first layout container, andfurther ensure that the first child view in the first layout container can present a better displayeffect. In other words, this application provides a layout container whose dimension can beadaptively adjusted based on a device parameter of an electronic device, so that a view in thelayout container can also be adaptively adjusted based on the device parameter of the electronicdevice. In this case, one layout file may be set for electronic devices having different deviceparameters, so as to prevent a developer from designing different layout files for the electronicdevices having different device parameters. In this way, this application reduces workload of thedeveloper in development and maintenance, and also meets display requirements of varioustypes of electronic devices.

[0061] It should be noted that an installation package of a general application includes aplurality of types of files such as a logic code file, a resource file, and a layout file. The layoutfile is used to define a graphical user interface (graphical user interface, GUI) (that is, a displayinterface), that is, define a hierarchical structure relationship between a view and a layoutcontainer on the display interface and attributes such as a dimension and a location. The logiccode file is execution logic behind a view and a layout container on the display interface. Theresource file includes content displayed in a view and a layout container on the display interface,for example, an image, a video, and a website.

[0062] In a possible implementation, a larger dimension of the first layout container in thefirst orientation indicates a larger dimension of the first child view in the first orientation.

[0063] In other words, on electronic devices having different device parameters, thedimension of the first child view in the first orientation increases as the dimension of the firstlayout container in the first orientation increases, so that the dimension of the first child view canbe adaptively adjusted on the electronic devices having different device parameters. In this way,the developer may set one layout file for the electronic devices having different deviceparameters.

[0064] In a possible implementation, the determining a dimension of a first child view in thefirst layout container in the first orientation based on the dimension of the first layout containerin the first orientation includes: determining that the dimension of the first child view in the firstorientation is the same as the dimension of the first layout container in the first orientation; ordetermining that the dimension of the first child view in the first orientation is the dimension ofthe first layout container in the first orientation minus an inner margin of the first layoutcontainer in the first orientation.

[0065] In an example, the dimension of the first child view in the first orientation is the sameas the dimension of the first layout container in the first orientation, and the first layout containerpresents the first child view as large as possible in the first orientation, so as to help the first childview display more content.

[0066] In another example, an inner margin of the first layout container may be further set.In this way, by ensuring that the first child view in the first layout container keeps a specificdistance from the edge of the first layout container, the display interface can present amagazine-like layout, for example, present a large white space, so that the display interfacepresents a magazine-like reading sense. This improves visual experience of the user.

[0067] In a possible implementation, the first orientation includes a horizontal orientationand / or a vertical orientation.

[0068] In other words, for the first layout container, the developer may set a stretchingcapability in one orientation, or may set stretching capabilities in two orientations. For example,if a stretching capability of the first layout container in the horizontal orientation is set, a widthof the first layout container varies with a width of the screen. If a stretching capability of the firstlayout container in the vertical orientation is set, a height of the first layout container varies witha height of the screen. If stretching capabilities of the first layout container in the horizontalorientation and the vertical orientation are set, the width of the first layout container varies withthe width of the screen, and the height of the first layout container varies with the height of thescreen.

[0069] In a possible implementation, when the first orientation is the horizontal orientation,the inner margin of the first layout container in the first orientation includes a left inner marginand / or a right inner margin, where the left inner margin is a distance from a left edge of aleftmost view in the layout container to a left edge of the layout container, and the right innermargin is a distance from a right edge of a rightmost view in the layout container to a right edgeof the layout container. When the first orientation is the vertical orientation, the inner margin ofthe first layout container in the first orientation includes an upper inner margin and / or a lowerinner margin, where the upper inner margin is a distance from an upper edge of an uppermostview in the layout container to an upper edge of the layout container, and the lower inner marginis a distance from a lower edge of a lowermost view in the layout container to a lower edge ofthe layout container.

[0070] In a possible implementation, the N child views each are any one of a text view, anedit view, a button view, and an image button view.

[0071] According to a second aspect, an electronic device is provided, including a processor,a memory, and a touchscreen. The memory, the touchscreen, and the processor are coupled, thememory is configured to store computer program code, the computer program code includescomputer instructions, and when the processor runs the computer instructions in the memory, theelectronic device is enabled to perform the method according to any one of the first aspect andthe possible implementations of the first aspect.

[0072] According to a third aspect, an apparatus is provided. The apparatus is included in anelectronic device, and the apparatus has functions of implementing behavior of the electronicdevice in the method according to any one of the first aspect and the possible implementations.The functions may be implemented by hardware, or may be implemented by hardware executingcorresponding software. The hardware or the software includes at least one module or unitcorresponding to the foregoing functions, for example, a receiving module or unit, a displaymodule or unit, and a processing module or unit.

[0073] According to a fourth aspect, a computer-readable storage medium is provided,including computer instructions. When the computer instructions are run on an electronic device,the electronic device is enabled to perform the method according to any one of the first aspectand the possible implementations of the first aspect.

[0074] According to a fifth aspect, a graphical user interface on an electronic device isprovided. The electronic device includes a display, a memory, and one or more processors. Theone or more processors are configured to execute one or more computer programs stored in thememory; and the graphical user interface includes a graphical user interface displayed when theelectronic device performs the method according to any one of the first aspect and the possibleimplementations of the first aspect.

[0075] According to a sixth aspect, a computer program product is provided. The computerprogram product includes computer instructions, and when the computer instructions are run ona computer, the computer is enabled to perform the method according to any one of the firstaspect and the possible implementations of the first aspect.

[0076] According to a seventh aspect, a chip system is provided, including a processor.When the processor executes instructions, the processor performs the method according to anyone of the first aspect and the possible implementations of the first aspect.

[0077] It can be understood that the electronic device, the apparatus, the computer-readablestorage medium, the computer program product, the graphical user interface, and the chip systemprovided in the foregoing aspects are all applied to the corresponding methods provided above.Therefore, for beneficial effects that can be achieved by the electronic device, the apparatus, thecomputer-readable storage medium, the computer program product, the graphical user interface,and the chip system, refer to the beneficial effects in the corresponding methods provided above.Details are not described herein again.BRIEF DESCRIPTION OF DRAWINGS

[0078] FIG. 1(1) and FIG. 1(2) are a schematic diagram of a structure of a display interfaceaccording to an embodiment of this application;

[0079] FIG. 2 is a schematic flowchart of an adaptive display interface layout methodaccording to an embodiment of this application;

[0080] FIG. 3 is a schematic flowchart of another adaptive display interface layout methodaccording to an embodiment of this application;

[0081] FIG. 4(1) and FIG. 4(2) are a schematic diagram of development interfaces of layoutfiles of some display interfaces according to an embodiment of this application;

[0082] FIG. 5 is a schematic diagram of a structure of an electronic device according to anembodiment of this application;

[0083] FIG. 6 is a schematic diagram of a structure of another electronic device according toan embodiment of this application;

[0084] FIG. 7A and FIG. 7B are a schematic diagram of another display interface layoutmethod according to an embodiment of this application;

[0085] FIG. 8 is a display effect diagram of a layout container having an extension capabilityin different scenarios according to an embodiment of this application;

[0086] FIG. 9 is a display effect diagram of another layout container having an extensioncapability in different scenarios according to an embodiment of this application;

[0087] FIG. 10A is a schematic flowchart of a measurement method in a view systemaccording to an embodiment of this application;

[0088] FIG. 10B(1) and FIG. 10B(2) are an effect diagram in which different electronicdevices display a layout container having an extension capability according to an embodiment ofthis application;

[0089] FIG. 11 is a schematic diagram of another adaptive application interface layoutmethod according to an embodiment of this application;

[0090] FIG. 12 is a display effect diagram of a layout container having a proportioncapability in different scenarios according to an embodiment of this application;

[0091] FIG. 13 is a display effect diagram of another layout container having a proportioncapability in different scenarios according to an embodiment of this application;

[0092] FIG. 14 is a display effect diagram of another layout container having a proportioncapability in different scenarios according to an embodiment of this application;

[0093] FIG. 15A(1) and FIG. 15A(2) are a schematic flowchart of another measurementmethod in a view system according to an embodiment of this application;

[0094] FIG. 15B(1) and FIG. 15B(2) are an effect diagram in which different electronicdevices display a layout container having a proportion capability according to an embodiment ofthis application;

[0095] FIG. 16 is a schematic diagram of another adaptive application interface layoutmethod according to an embodiment of this application;

[0096] FIG. 17 is a display effect diagram of a layout container having an equalizationcapability in different scenarios according to an embodiment of this application;

[0097] FIG. 18 is a display effect diagram of another layout container having an equalizationcapability in different scenarios according to an embodiment of this application;

[0098] FIG. 19 is a display effect diagram of another layout container having an equalizationcapability in different scenarios according to an embodiment of this application;

[0099] FIG. 20 is a display effect diagram of another layout container having an equalizationcapability in different scenarios according to an embodiment of this application;

[00100] FIG. 21A is a schematic flowchart of another measurement method in a view systemaccording to an embodiment of this application;

[00101] FIG. 21B(1) and FIG. 21B(2) are an effect diagram in which different electronicdevices display a layout container having an equalization capability according to an embodimentof this application;

[00102] FIG. 22 is a schematic diagram of another adaptive application interface layoutmethod according to an embodiment of this application;

[00103] FIG. 23 is a display effect diagram of a layout container having a hiding capability indifferent scenarios according to an embodiment of this application;

[00104] FIG. 24A is a schematic flowchart of another measurement method in a view systemaccording to an embodiment of this application;

[00105] FIG. 24B is a schematic flowchart of another measurement method in a view systemaccording to an embodiment of this application;

[00106] FIG. 25 is an effect diagram in which different electronic devices display a layoutcontainer having a hiding capability according to an embodiment of this application;

[00107] FIG. 26 is a schematic diagram of another adaptive application interface layoutmethod according to an embodiment of this application;

[00108] FIG. 27 is a display effect diagram of a layout container having a stretching capabilityin different scenarios according to an embodiment of this application;

[00109] FIG. 28 is a display effect diagram of another layout container having a stretchingcapability in different scenarios according to an embodiment of this application;

[00110] FIG. 29 is a display effect diagram of another layout container having a stretchingcapability in different scenarios according to an embodiment of this application;

[00111] FIG. 30A(1) and FIG. 30A(2) are a schematic flowchart of another measurementmethod in a view system according to an embodiment of this application;

[00112] FIG. 30B is an effect diagram in which different electronic devices display a layoutcontainer having a stretching capability according to an embodiment of this application;

[00113] FIG. 31 is a display effect diagram of some layout containers having a plurality ofadaptive layout capabilities in different scenarios according to an embodiment of thisapplication;

[00114] FIG. 32(1) and FIG. 32(2) are a display effect diagram of some other layoutcontainers having a plurality of adaptive layout capabilities in different scenarios according to anembodiment of this application;

[00115] FIG. 33(1) to FIG. 33(3) are a display effect diagram of some other layout containershaving a plurality of adaptive layout capabilities in different scenarios according to anembodiment of this application;

[00116] FIG. 34 is a display effect diagram of some other layout containers having a pluralityof adaptive layout capabilities in different scenarios according to an embodiment of thisapplication;

[00117] FIG. 35(1) and FIG. 35(2) are a display effect diagram of some other layoutcontainers having a plurality of adaptive layout capabilities in different scenarios according to anembodiment of this application;

[00118] FIG. 36(1) to FIG. 36(3) are a display effect diagram of some other layout containershaving a plurality of adaptive layout capabilities in different scenarios according to anembodiment of this application;

[00119] FIG. 37(1) and FIG. 37(2) are a display effect diagram of some other layoutcontainers having a plurality of adaptive layout capabilities in different scenarios according to anembodiment of this application;

[00120] FIG. 38(1) and FIG. 38(2) are a display effect diagram of some other layoutcontainers having a plurality of adaptive layout capabilities in different scenarios according to anembodiment of this application; and

[00121] FIG. 39 is a schematic diagram of a structure of a chip system according to anembodiment of this application.DESCRIPTION OF EMBODIMENTS

[00122] In the descriptions of embodiments of this application, unless otherwise specified, " / "means "or". For example, A / B may represent A or B. In this specification, "and / or" describesonly an association relationship between associated objects and represents that threerelationships may exist. For example, A and / or B may represent the following three cases: OnlyA exists, both A and B exist, and only B exists. Terms "first" and "second" below are merelyintended for a purpose of description, and shall not be understood as an indication or implicationof relative importance or implicit indication of a quantity of indicated technical features.Therefore, a feature limited by "first" or "second" may explicitly or implicitly include one ormore features. In the descriptions of embodiments of this application, unless otherwise specified,"a plurality of" means two or more. In embodiments of this application, a word "example" or"for example" is used to represent giving an example, an illustration, or a description. Anyembodiment or design scheme described as an "example" or "for example" in embodiments ofthis application should not be explained as being more preferred or having more advantages thananother embodiment or design scheme. Exactly, use of the word such as "example" or "forexample" is intended to present a relative concept in a specific manner.

[00123] An Android system is used as an example for description. An application defines agraphical user interface (graphical user interface, GUI) (that is, a display interface) by using alayout file. The layout file includes a view tree, and the view tree includes a view and a layoutcontainer.

[00124] The view is an element presented on the GUI, and can provide a specific operationfunction for a user or can be used to display specific content. For example, the view mayspecifically include a text view such as a TextView view and an EditText view, or may include abutton view such as a Button view and an ImageButton view, or may include an image view suchas an ImageView view. This is not limited in embodiments of this application.

[00125] The layout container is configured to store a view and a layout structure of anotherlayout container. In other words, one layout container may include one or more views, and nestone or more layout containers.

[00126] A display interface of the Android system is used as an example for description.Generally, one display interface corresponds to one Activity, one Activity holds one Windowobject (for example, a PhoneWindow), and the Window is used to draw various views. As a mostbasic window system of the Android system, the PhoneWindow has a top-level View objectDecorView (actually, one ViewGroup). The DecorView is a root view (ViewRoot) of all Viewsand ViewGroups, and is also referred to as a root node view. The DecorView includes aContentView (actually, one ViewGroup). The ContentView is a view customized by eachapplication, that is, a display interface of the application. The ContentView is also referred to asa content view. The ContentView includes one or more Views and / or one or more ViewGroups.It should be noted that, in an interface display process, an electronic device traverses an entireview tree from top to bottom starting from a performTraversals() method of a root view, eachView is responsible for drawing the View, and a ViewGroup further needs to be responsible forindicating a child View of the ViewGroup to perform a drawing operation. Optionally, theDecorView further includes a TitleView (title view), which may be used to customize navigationof the display interface.

[00127] FIG. 1(1) is a schematic diagram of an alarm clock interface 10. The alarm clockinterface 10 corresponds to one DecorView. The DecorView includes View1 (text view), View2(image view), and ViewGroup1. ViewGroup1 specifically includes ViewGroup2, ViewGroup3,and View7 (button view). ViewGroup2 includes View3 (text view) and View4 (button view).Similarly, ViewGroup3 includes View5 (text view) and View6 (button view). For a hierarchicalstructure relationship between each View and each ViewGroup on the alarm clock interface 10,refer to a view tree shown in FIG. 1(2).

[00128] For example, a developer may design a View or a ViewGroup on each displayinterface in an application in a layout manner such as a linear layout (LinearLayout) manner, atable layout (TableLayout) manner, a relative layout (RelativeLayout) manner, a frame layout(FrameLayout) manner, an absolute layout (AbsoluteLayout) manner, or a grid layout(GridLayout) manner, to generate a layout file of each display interface, that is, a layout file.

[00129] In other words, the developer may set a hierarchical structure of each View and eachViewGroup on the display interface and an attribute value (for example, a dimension (a widthand a height) and a location) in the layout file of each display interface. Then, the layout files ofthese display interfaces are packed into an installation package of the application, and theinstallation package of the application is released to an application market. Subsequently, anelectronic device may download the installation package of the application from the applicationmarket and install the installation package of the application. When an application runs in theelectronic device, the electronic device may obtain a layout file of the application, draw acorresponding display interface based on the layout file, and present the display interface to auser.

[00130] It should be noted that, in one solution, in the layout file of the display interface, theremay be determined attribute values for the View and the ViewGroup included in the displayinterface. Once the attribute values of each View and each ViewGroup on the display interfaceare set in the layout file, the dimension and the location of the View or the ViewGroup on thedisplay interface remain unchanged. In other words, when developing the application, thedeveloper has determined an appearance of each display interface presented to the user. It can beunderstood that, when electronic devices having different screen specifications draw a samedisplay interface by using the layout file, or the entire display interface is simply scaled down orscaled up, because the screen specifications of the electronic devices are different currently,reusing a same display interface often causes a poor display effect. Currently, developers of someapplications design different layout files for displays having different specifications, and adapt tocorresponding logic, causing huge development and maintenance workload. In addition, a largequantity of layout files are packed into an installation package of an application, causing anexcessively large installation package of the application and affecting a speed of downloadingthe installation package by an electronic device and a space occupied by storing the installationfile after installation.

[00131] In another technical solution, for an electronic device having a large screen dimension,layout files of a plurality of small-sized electronic devices may be directly reused. For example,a large-screen dimension is a tablet computer, and a dimension of a screen of the tablet computeris 1280*800 pixels; and a small-screen dimension is a mobile phone, and a dimension of a screenof the mobile phone is 720*1080 pixels. In this case, when the tablet computer displays anapplication interface, the tablet computer may simultaneously display two or more windows, andeach window uses a layout file of one display interface corresponding to the mobile phone. Inother words, that the tablet computer displays one display interface is equivalent to that themobile phone simultaneously displays two or more display interfaces. For example, the screen ofthe tablet computer is evenly divided into two windows, and a size of each window may be640*800 pixels. Each window is used to display one interface of the mobile phone. Obviously,an aspect ratio of one window on the tablet computer is 640:800 (that is, 4:5), and an aspect ratioof an interface of the mobile phone is 720:1080 (that is, 2:3).

[00132] It should be noted that, even if a large-sized electronic device may reuse layout filesof a plurality of small-sized electronic devices in a multi-window management manner, an aspectratio of each window on the large-sized electronic device is inconsistent with an aspect ratio of asmall-sized electronic device in most cases. Consequently, directly reusing a layout file of asmall-sized electronic device cannot present a relatively good interface layout.

[00133] An embodiment of this application provides a display interface layout method, todevelop one layout file for one display interface of an application. The layout file is applicable tovarious electronic devices having different screen specifications. This is because an electronicdevice may adaptively adjust a display interface layout based on a screen parameter of theelectronic device when running the application. This improves display effects of electronicdevices having different screen specifications, and also reduces development and maintenancecosts of a developer. The screen parameter includes a screen specification (dimension) parameterand a screen status parameter (for example, a landscape / portrait state and a folding state of afoldable screen).

[00134] In addition, even if electronic devices of a same or similar type have different screenparameters, most use scenarios (user interaction manners, function views, or the like) are similar.Therefore, display interfaces presented to a user are usually similar. Therefore, designing onelayout file for one application can meet a design intention of an application developer. However,electronic devices having different screen parameters adaptively adjust a dimension and / or alocation of a View and a ViewGroup in a layout file on a display interface based on adaptivelayout capabilities of the View and the ViewGroup, so as to weaken display limitations ofdifferent electronic devices. This helps the user switch between different electronic devices fordisplay, and meets display requirements of the user in different scenarios. For example, in adistributed display scenario, the user may send display interfaces corresponding to differentfunction modules on one display interface to different electronic devices for display. For anotherexample, based on a current application scenario (a driving scenario, a home scenario, a fitnessscenario, or the like), the user switches between different electronic devices to display a displayinterface.

[00135] For example, when designing a layout file of each display interface in an application,a developer of the application may set, for a View and a ViewGroup included in the displayinterface, attribute values extended in this embodiment of this application. These extendedattribute values do not uniquely determine a dimension and a location of the View or theViewGroup, but restrict a relative relationship (for example, a relative size relationship or arelative location relationship) between the View or the ViewGroup and another View (or anotherViewGroup) on the display interface. In other words, when developing the application, thedeveloper does not determine an appearance of each display interface presented to the user.Subsequently, when drawing the display interface by using the layout file, the electronic deviceobtains a screen parameter of the electronic device, determines a display parameter (for example,a display location and a display size of the display interface on a screen of the electronic device)of the display interface, and performs layout on a dimension, a location, and the like of eachView and each ViewGroup on the display interface based on hierarchical structures and extendedattribute values of each View and each ViewGroup included in the display interface in the layoutfile, and the screen parameter of the electronic device. For example, when running theapplication, the electronic device determines, based on the screen parameter of the electronicdevice, an appearance of each display interface presented to the user. It can be understood thatelectronic devices having different screen parameters draw different display interfaces based on asame layout file.

[00136] In some other embodiments, the solution provided in this embodiment of thisapplication may also be used in combination with a solution in which a large-sized screen reusesa layout file of a small-sized screen. For example, an electronic device having a large-sizedscreen may reuse a plurality of layout files of small-sized electronic devices in a multi-windowmanagement manner. It should be noted that the plurality of layout files of the small-sizedelectronic devices herein respectively correspond to different display interfaces. In other words,one display interface of the application herein still corresponds to one layout file.

[00137] Therefore, when displaying a display interface in each window, the electronic devicehaving a large-sized screen adaptively adjusts a dimension, a location, and the like of each Viewand each ViewGroup on the display interface based on a layout file of the display interfacecorresponding to the window and a dimension of the window. In other words, even if an aspectratio of each window on the electronic device having a large-sized screen is inconsistent with anaspect ratio of the electronic device having a small-sized screen, according to the adaptive layoutsolution provided in this embodiment of this application, the interface displayed in each windowon the electronic device having a large-sized screen can still present a relatively good displayeffect.

[00138] As shown in FIG. 2, in a development phase, a developer develops one layout file(the layout file includes a View and a ViewGroup that are provided with extended attributevalues in this application) for each display interface of an application on a developer device (forexample, a computer) by using a related development tool, packs the layout file into aninstallation package of the application, and uploads the application installation package to aserver (cloud). Subsequently, all electronic devices (for example, electronic devices of differenttypes or electronic devices of a same type but different models) having different screenparameters may download the application installation package from the server, and run theapplication installation package. It can be learned that each of these different electronic devicesobtains a screen parameter of the electronic device, and determines a display parameter of thedisplay interface of the application (for example, a display location and a display size of thedisplay interface of the application on a screen of the electronic device). Then, the View and theViewGroup on the display interface of the application are arranged with reference to the displayparameter of the application and the layout file in the foregoing application installation package,and a corresponding display interface is displayed. For example, a mobile phone draws aninterface 21 shown in 1B, a smartwatch draws an interface 22 shown in 1B, and Vision draws aninterface 23 shown in 1B.

[00139] It should be noted that, in this specification, a View or a ViewGroup having anextended attribute is also referred to as a View or a ViewGroup having an adaptive layoutcapability. In other words, in this embodiment of this application, each View or each ViewGroupon the display interface has an adaptive layout capability. The adaptive layout capability of theView or the ViewGroup may be implemented by using a code module. The following describesan implementation process in detail by using a scaling capability as an example.

[00140] The adaptive layout capability of the View or the ViewGroup includes but is notlimited to a scaling capability, a stretching capability, a hiding capability, a wrapping capability(which may also be referred to as an automatic branching capability), an equalization capability,a proportion capability, and an extension capability. The adaptive layout capability of the Viewor the ViewGroup is briefly described herein, and is described in detail below.

[00141] The scaling capability means that the View or the ViewGroup has a capability ofadaptively scaling down or scaling up in a horizontal orientation and a vertical orientation in alayout container. For example, a proportion of the View or the ViewGroup in a specifiedorientation in the layout container may be set. In this way, when a dimension of the layoutcontainer changes, the View or the ViewGroup in the layout container keeps an original shape(for example, an aspect ratio) for scaling, so that a proportion of the View or the ViewGroup inthe horizontal orientation in the layout container reaches a specified proportion after scaling,and / or a proportion of the View or the ViewGroup in the vertical orientation in the layoutcontainer reaches a specified proportion after scaling.

[00142] The stretching capability means that the View or the ViewGroup has an adaptivestretching capability in a specified orientation in the layout container. For example, a marginvalue of the View or the ViewGroup in the specified orientation (horizontal and / or vertical) in thelayout container may be set. The margin value is a distance between the View or the ViewGroupand an edge of the layout container. In this way, when the dimension of the layout containerchanges, the View or the ViewGroup in the layout container maintains a margin with the layoutcontainer in the specified orientation, and adaptively changes with the dimension of the layoutcontainer in the specified orientation.

[00143] It should be noted that stretching in this embodiment of this application includesscaling up (the dimension is increased) and scaling down (the dimension is decreased) of theView or the ViewGroup in the specified orientation. For example, the View or the ViewGroup ishorizontally stretched, including a width increase or a width decrease of the View or theViewGroup. The View or the ViewGroup is vertically stretched, including a height increase or aheight decrease of the View or the ViewGroup.

[00144] The hiding capability is a capability of automatically hiding the View or theViewGroup based on a priority during display. For example, a hiding priority of the View or theViewGroup in the layout container may be set. A hiding priority is used as an example. When thedimension of the layout container changes and is insufficient to display all designed Views orViewGroups, hiding is performed based on a hiding priority of each View or ViewGroup.

[00145] The wrapping capability means that the View or the ViewGroup in the layoutcontainer has an adaptive wrapping capability. For example, a wrapping reference value of thelayout container may be set. When a total width and spacing of a row of Views or ViewGroups inthe layout container are greater than the wrapping reference value, another View or ViewGroupgreater than the wrapping reference value is automatically wrapped for display.

[00146] It should be noted that the wrapping capability herein includes horizontal wrappingand vertical wrapping. The horizontal wrapping means that a plurality of child views areoriginally arranged horizontally, and the electronic device may automatically determine todisplay the plurality of child views in separate lines based on a width of the layout containerduring display. The vertical wrapping means that a plurality of child views are originallyarranged vertically, and the electronic device may automatically determine to display theplurality of child views in separate columns based on a height of the layout container duringdisplay. In some other examples, the vertical wrapping may also be considered as an inverseoperation of the horizontal wrapping. Therefore, the wrapping capability in this application mayalso be expressed as a branching capability, a column capability, a segmentation capability, asection capability, or the like. This is not specifically limited in this embodiment of thisapplication.

[00147] The equalization capability means that the View or the ViewGroup in the layoutcontainer has an automatic spacing adjustment capability. For example, a spacing between Viewsor ViewGroups in a specified orientation in the layout container may be set to be evenly divided.In this case, when the dimension of the layout container changes, the View or the ViewGroup inthe layout container adaptively adjusts the spacing of the View or the ViewGroup in the layoutcontainer based on the dimension of the View or the ViewGroup and the dimension of the layoutcontainer.

[00148] The proportion capability is a capability that the View or the ViewGroup maintains afixed proportion in a specified orientation in the layout container. For example, a proportion ofthe layout container in the specified orientation (for example, a horizontal orientation or avertical orientation) may be set. In this way, when the dimension of the layout container changes,the View or the ViewGroup in the layout container keeps an original shape (for example, anaspect ratio) for scaling, so that a proportion of the View or the ViewGroup in the specifiedorientation in the layout container meets a specified proportion after scaling.

[00149] The extension capability means that the layout container has a capability ofautomatically adjusting a quantity of displayed child views (Views or ViewGroups). Theextension capability includes a general extension capability and an extended extension capability.The general extension capability means that, when the dimension of the layout container changes,a quantity of child views that are completely displayed in the layout container is determinedbased on the dimension of the layout container, a dimension of a child view in the layoutcontainer, and a default spacing. The completely displayed child view, also referred to as a fullydisplayed child view, means that all content of the child view is displayed in the layout container.The extended extension capability means that the layout container can further display a childview that is not completely displayed. The incompletely displayed child view, also referred to asa non-fully displayed child view or a partially displayed child view, means that partial content ofthe child view is displayed in the layout container. For example, a dimension threshold in thelayout container may be set. In this case, when the dimension of the layout container changes, adimension of the completely displayed child view and a dimension of the partially displayedcontent of the incompletely displayed child view in the layout container are determined based ona dimension of a child view in the layout container, the dimension of the layout container, andthe dimension threshold.

[00150] It should be noted that the extension capability includes a horizontal extensioncapability and a vertical extension capability. The horizontal extension capability means that aquantity of displayed child views is determined based on the width of the layout container forhorizontally arranged child views. The vertical extension capability means that a quantity ofdisplayed child views is determined based on the height of the layout container for verticallyarranged child views. This specification uses the horizontal extension capability as an examplefor description. For the vertical extension capability, refer to an implementation of the horizontalextension capability. Details are not described in this specification.

[00151] FIG. 3 shows a general procedure of implementing an adaptive layout capability of aView or a ViewGroup according to an embodiment of this application. First, a developer uses adevelopment tool to develop an application interface. In a development process, a capability thatneeds to be used may be selected from View and ViewGroup capability libraries (including anAndroid native capability and an adaptive layout capability extended in this application) toobtain a layout file, to complete application interface development and generate an installationpackage of an application. Then, an electronic device may download the application installationpackage from an application market, and install and run the application installation package.When running the application, the electronic device completes an automatic layout based on thelayout file and an environment (for example, a screen parameter) of the electronic device, anddraws a corresponding application interface, that is, a user-viewed interface.

[00152] The following describes a specific solution of implementing an adaptive layoutcapability of a View or a ViewGroup in this application.

[00153] When developing an application, a developer uses an integrated developmentenvironment (Integrated Development Environment, IDE) tool to develop the application. TheIDE tool integrates an integrated software development service set including a code writingfunction, an analysis function, a compilation function, a debugging function, and the like. Forexample, a typical IDE tool of an Android system includes any one of Android Studio andDevEco Studio.

[00154] FIG. 4(1) shows an example of a development interface 20 displayed when adeveloper develops an application. The development interface 20 includes an applicationdirectory tree 21, an application dependency package 22, and a development interface of anapplication display interface 1. The development interface of the application display interface 1includes a layout file (for example, 111.xml) 23 and Java source code (for example, 222.java) 24.

[00155] The application directory tree 21 includes an application name, a compilationdependency package, an application package, and application source code. The developer mayquickly open a corresponding file by using the application directory tree 21, so that the developercan conveniently edit the file. For example, the developer may quickly open a Java source codefile or a layout file by using the Java source code or the layout file in the application source code,and the developer may edit the Java source code file or the layout file to edit a layout of eachdisplay interface in the application.

[00156] It should be noted that, before the layout of the display interface is edited, a library onwhich application development depends needs to be added. Specifically, the dependency librarymay be added to the application dependency package 22. For example, developing an applicationon the Android system needs to depend on an extended library (External Libs) and an AndroidAPI library.

[00157] After adding the dependency library, the developer may set information such ashierarchical structures and attribute values of a View and a ViewGroup included in each displayinterface in the application and a display resource of each View by invoking a corresponding APIinterface in the Java source code 24, or the developer may set information such as hierarchicalstructures and attribute values of a View and a ViewGroup included in each display interface inthe application and a display resource of each View in the layout file 23.

[00158] It should be noted that the View and the ViewGroup provided in this embodiment ofthis application have adaptive layout capabilities. In addition to a basic library (External Libs orAndroid API library) of the Android system, an extended library in this application such as anadaptive layout attribute package further needs to be depended on. In a specific implementation,the adaptive layout attribute package includes a declaration of each adaptive layout capability ofthe View and the ViewGroup, information about an interface invoked by each adaptive layoutcapability, and a preset algorithm corresponding to each adaptive layout capability (the presetalgorithm may include a measurement procedure used for a layout of a layout container providedwith each adaptive layout capability, and the like). Therefore, when developing the application,the developer designs a layout file of the application by using the declaration of each adaptivelayout capability, the information about the interface invoked by each adaptive layout capability,or the like. In other words, the layout file includes the View or the ViewGroup provided with theadaptive layout capability. The developer packs the designed layout file, the preset algorithmcorresponding to each adaptive layout capability, and other program code and resources requiredby the application into the installation package of the application. In another specificimplementation, the developer designs a layout file of the application by using the declaration ofeach adaptive layout capability or the information about the interface invoked by each adaptivelayout capability, and packs the designed layout file of the application and other program codeand resources required by the application into the installation package of the application. In thisexample, an electronic device that subsequently installs the installation package of theapplication needs to have each adaptive layout capability provided in this embodiment of thisapplication, for example, pre-installs an algorithm module corresponding to each adaptive layoutcapability.

[00159] In other words, in a specific embodiment, the application installation package packedby the developer includes the layout file and the preset algorithm that corresponding to theadaptive layout capability that is set in the layout file. In another specific embodiment, theapplication installation package packed by the developer includes the layout file, but may notinclude the preset algorithm corresponding to the adaptive layout capability that is set in thelayout file. In this embodiment, an electronic device that subsequently runs the applicationinstallation package pre-installs a preset algorithm module corresponding to the adaptive layoutcapability that is set in the layout file. For example, a pre-installed operating system of theelectronic device includes the preset algorithm module corresponding to the adaptive layoutcapability, or the electronic device may download the preset algorithm module corresponding tothe adaptive layout capability from a server (for example, a server that provides the adaptivelayout capability or a server of the electronic device) and install the preset algorithm module.

[00160] After downloading and installing the installation package of the application, andwhen running the application, the electronic device may obtain an attribute value of the View orthe ViewGroup of the adaptive layout capability based on the interface invoked by each adaptivelayout capability, invoke a processing procedure corresponding to layout measurement of eachadaptive layout capability to complete measurement and a layout, and finally draw a displayinterface. The interface invoked by each adaptive layout capability and the processing procedurecorresponding to each adaptive layout capability (for example, the preset algorithmcorresponding to each adaptive layout capability) are described in detail in the following when aprocessing procedure of the electronic device is described.

[00161] For example, as shown in FIG. 4(1), the developer may add an adaptive layoutattribute package by using a view 25. As shown in a development interface 27 in FIG. 4(2), anadaptive layout attribute package 26 is newly added to the application dependency package.

[00162] It can be learned from the layout file 23 that "android:" guides an attribute value of anative View or ViewGroup of the Android system; and "app:" guides an attribute value of anextended View or ViewGroup in this application, that is, an attribute value of a View or aViewGroup having an adaptive layout capability. Alternatively, it can be learned from the Javasource code 24 that an API interface corresponding to the adaptive layout capability invoked bythe developer includes, for example, setAttr1(), getAttr1(), setAttr2(), and getAttr2().

[00163] Then, the developer uses the IDE tool to pack the source code, the resources(including the layout file), the dependency library, and the like of the developed application intothe installation package (for example, an APK file). In other words, the developer completes thedevelopment of the application. Then, the installation package of the application is released to anapplication market. A user may download and install the application on different electronicdevices. It should be noted that electronic devices having different screen parameters draw adisplay interface of the application by using a same layout file.

[00164] For example, the electronic device in this embodiment of this application may be amobile phone, a tablet computer, a personal computer (personal computer, PC), a personal digitalassistant (personal digital assistant, PDA), a netbook, a wearable electronic device (such as asmart band or a smartwatch), an augmented reality (augmented reality, AR) device, a virtualreality (virtual reality, VR) device, a vehicle-mounted device, Vision, a smart car, or a smartspeaker. A specific form of the electronic device is not limited in this application.

[00165] FIG. 5 is a schematic diagram of a structure of an electronic device 100. It may beunderstood that the structure shown in this embodiment of this application does not constitute aspecific limitation on the electronic device 100. In some other embodiments of this application,the electronic device 100 may include more or fewer components than those shown in the figure,or some components may be combined, or some components may be split, or differentcomponent arrangements may be used. The components shown in the figure may beimplemented by hardware, software, or a combination of software and hardware.

[00166] The electronic device 100 may include a processor 110, an external memory interface120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, acharging management module 140, a power management module 141, a battery 142, an antenna1, an antenna 2, a mobile communications module 150, a wireless communications module 160,an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headset jack 170D,a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, asubscriber identity module (subscriber identity module, SIM) card interface 195, and the like.

[00167] The processor 110 may include one or more processing units. For example, theprocessor 110 may include an application processor (application processor, AP), a modemprocessor, a graphics processing unit (graphics processing unit, GPU), an image signal processor(image signal processor, ISP), a controller, a video codec, a digital signal processor (digitalsignal processor, DSP), a baseband processor, and / or a neural-network processing unit(neural-network processing unit, NPU). Different processing units may be independentcomponents, or may be integrated into one or more processors.

[00168] A memory may be further disposed in the processor 110, and is configured to storeinstructions and data. In some embodiments, the memory in the processor 110 is a cache. Thememory may store instructions or data just used or cyclically used by the processor 110. If theprocessor 110 needs to use the instructions or the data again, the processor may directly invokethe instructions or the data from the memory. This avoids repeated access, reduces a waiting timeof the processor 110, and improves system efficiency.

[00169] The internal memory 121 may be configured to store computer-executable programcode. The executable program code includes instructions. The internal memory 121 may includea program storage area and a data storage area. The program storage area may store an operatingsystem, an application required by at least one function (for example, a voice playing function oran image playing function), and the like. The data storage area may store data (such as audio dataand an address book) created during use of the electronic device 100, and the like. In addition,the internal memory 121 may include a high-speed random access memory, or may include anonvolatile memory, for example, at least one magnetic disk storage device, a flash memory, or auniversal flash storage (universal flash storage, UFS). The processor 110 runs instructions storedin the internal memory 121 and / or instructions stored in the memory disposed in the processor, toperform various function applications and data processing of the electronic device 100.

[00170] The external memory interface 120 may be used to connect to an external storagecard, for example, a micro SD card, to extend a storage capability of the electronic device 100.The external memory card communicates with the processor 110 through the external memoryinterface 120, to implement a data storage function. For example, files such as music and videosare stored in the external storage card.

[00171] The charging management module 140 is configured to receive a charging input fromthe charger. The charger may be a wireless charger or a wired charger. In some embodiments ofwired charging, the charging management module 140 may receive a charging input of a wiredcharger through the USB interface 130. In some embodiments of wireless charging, the chargingmanagement module 140 may receive a wireless charging input through a wireless charging coilof the electronic device 100. The charging management module 140 supplies power to theelectronic device through the power management module 141 while charging the battery 142.

[00172] The power management module 141 is configured to connect to the battery 142, thecharging management module 140, and the processor 110. The power management module 141receives an input from the battery 142 and / or the charging management module 140, andsupplies power to the processor 110, the internal memory 121, the display 194, the camera 193,the wireless communications module 160, and the like. The power management module 141 maybe further configured to monitor parameters such as a battery capacity, a battery cycle count, anda battery health status (electric leakage or impedance). In some other embodiments, the powermanagement module 141 may alternatively be disposed in the processor 110. In some otherembodiments, the power management module 141 and the charging management module 140may alternatively be disposed in a same device.

[00173] A wireless communication function of the electronic device 100 may be implementedthrough the antenna 1, the antenna 2, the mobile communications module 150, the wirelesscommunications module 160, the modem processor, the baseband processor, and the like. Themobile communications module 150 may provide a solution, applied to the electronic device 100,to wireless communication including 2G, 3G, 4G, 5G, or the like. The wireless communicationsmodule 160 may provide a wireless communication solution that is applied to the electronicdevice 100, and that includes a wireless local area network (wireless local area network, WLAN)(for example, a wireless fidelity (wireless fidelity, Wi-Fi) network), Bluetooth (Bluetooth, BT), aglobal navigation satellite system (global navigation satellite system, GNSS), frequencymodulation (frequency modulation, FM), a near field communication (near field communication,NFC) technology, an infrared (infrared, IR) technology, or the like.

[00174] In some embodiments, in the electronic device 100, the antenna 1 and the mobilecommunications module 150 are coupled, and the antenna 2 and the wireless communicationsmodule 160 are coupled, so that the electronic device 100 can communicate with a network andanother device by using a wireless communications technology. The wireless communicationstechnology may include a global system for mobile communications (global system for mobilecommunications, GSM), a general packet radio service (general packet radio service, GPRS),code division multiple access (code division multiple access, CDMA), wideband code divisionmultiple access (wideband code division multiple access, WCDMA), time-division code divisionmultiple access (time-division code division multiple access, TD-SCDMA), long term evolution(long term evolution, LTE), BT, a GNSS, a WLAN, NFC, FM, an IR technology, and / or the like.The GNSS may include a global positioning system (global positioning system, GPS), a globalnavigation satellite system (global navigation satellite system, GLONASS), a BeiDou navigationsatellite system (BeiDou navigation satellite system, BDS), a quasi-zenith satellite system(quasi-zenith satellite system, QZSS), and / or a satellite based augmentation system (satellitebased augmentation system, SBAS).

[00175] The electronic device 100 may implement a display function through the GPU, thedisplay 194, the application processor, and the like. The electronic device 100 may implement aphotographing function through the camera 193, the ISP, the video codec, the GPU, the display194, the application processor and the like. The electronic device 100 may implement an audiofunction such as music playing and recording through the audio module 170, the speaker 170A,the receiver 170B, the microphone 170C, the headset jack 170D, the application processor, andthe like.

[00176] The button 190 includes a power button, a volume button, and the like. The button190 may be a mechanical button, or may be a touch button. The electronic device 100 mayreceive a key input, and generate a key signal input related to a user setting and function controlof the electronic device 100. The motor 191 may generate a vibration prompt. The motor 191may be configured to provide an incoming call vibration prompt and a touch vibration feedback.For example, touch operations performed on different applications (for example, photographingand audio playback) may correspond to different vibration feedback effects. The motor 191 mayalso correspond to different vibration feedback effects for touch operations performed ondifferent areas of the display 194. Different application scenarios (for example, a time reminder,information receiving, an alarm clock, and a game) may also correspond to different vibrationfeedback effects. A touch vibration feedback effect may be further customized. The indicator 192may be an indicator light, and may be configured to indicate a charging status and a powerchange, or may be configured to indicate a message, a missed call, a notification, and the like.The SIM card interface 195 is configured to connect to a SIM card.

[00177] The sensor module 180 may include a touch sensor. The touch sensor is also referredto as a "touch component". The touch sensor may be disposed on the display 194, and the touchsensor and the display 194 form a touchscreen, which is also referred to as a "touch screen". Thetouch sensor is configured to detect a touch operation performed on or near the touch sensor. Thetouch sensor may transfer the detected touch operation to the application processor to determinea type of the touch event. A visual output related to the touch operation may be provided throughthe display 194. In some other embodiments, the touch sensor may alternatively be disposed on asurface of the electronic device 100, and is at a location different from that of the display 194.

[00178] FIG. 6 is a block diagram of a software structure of an electronic device 100according to an embodiment of the present invention.

[00179] In a layered architecture, software is divided into several layers, and each layer has aclear role and task. The layers communicate with each other through a software interface. Insome embodiments, the Android system is divided into four layers: an application layer, anapplication framework layer, an Android runtime (Android runtime) and system library, and akernel layer from top to bottom.

[00180] The application layer may include a series of application packages. As shown in FIG.6, the application packages may include a gallery application, a clock application, and the like. Itshould be noted that the gallery application or the clock application herein is an applicationinstalled by using the foregoing application installation package. In other words, a layout filecorresponding to the gallery application, the clock application, or the like includes a View or aViewGroup provided with the foregoing adaptive layout capability.

[00181] The application framework layer provides an application programming interface(application programming interface, API) and a programming framework for an application atthe application layer. The application framework layer includes some predefined functions. Asshown in FIG. 6, the application framework layer may include an activity manager system(Activity Manager System, AMS), a resource manager (Resource Manager), a window managersystem (Window Manager System, WMS) (not shown in the figure), and a view system (ViewSystem).

[00182] The AMS is configured to control all aspects of an application life cycle and anactivity stack. The resource manager is configured to provide access to a non-code embeddedresource such as a string, a color setting, and a user interface layout. The WMS is configured toobtain a display size, determine whether there is a status bar, perform screen locking, take ascreenshot, and the like. The view system is configured to provide a view set for creating anapplication user interface.

[00183] Specifically, after an application (for example, the clock application) is started, theAMS responds to a touch (Touch) event, and starts a main Activity. In the main Activity, attributevalues of a View or a ViewGroup included in the display interface are read from the resourcemanager by performing an inflate procedure in setContentView. In some examples, a layout fileis first read in the resource manager, and then a corresponding interface is invoked by using thelayout file, to write the attribute values of each View and each ViewGroup included in thedisplay interface. In some other examples, an interface may alternatively be directly invoked inthe resource manager, to write the attribute values of each View and each ViewGroup included inthe display interface. It should be noted that the attribute values of the View and the ViewGroupherein include an Android native attribute value and an attribute value related to an adaptivelayout capability in this application. Then, a window drawing procedure of the view system isentered, and drawing of the display interface is completed by performing three procedures:measurement (Measure), layout (Layout), and draw (Draw). The measurement procedureincludes an Android native measurement procedure and an extended measurement procedurerelated to the adaptive layout capability in this application.

[00184] The Android runtime includes a kernel library and a virtual machine. The Androidruntime is responsible for scheduling and management of the Android system.

[00185] The kernel library includes two parts: a function that needs to be called in Javalanguage and a kernel library of Android.

[00186] The application layer and the application framework layer run on the virtual machine.The virtual machine executes Java files of the application layer and the application frameworklayer as binary files. The virtual machine is configured to implement functions such as objectlifecycle management, stack management, thread management, security and exceptionmanagement, and garbage collection.

[00187] The system library may include a plurality of function modules, for example, asurface manager (surface manager), a media library (Media Library), a three-dimensionalgraphics processing library (for example, OpenGL ES), and a 2D graphics engine (for example,SGL).

[00188] The surface manager is configured to manage a display subsystem, and providefusion of 2D and 3D layers for a plurality of applications. The media library supports playbackand recording in a plurality of commonly used audio and video formats, and static image files.The media library may support a plurality of audio and video coding formats, for example,MPEG-4, H.264, MP3, AAC, AMR, JPG, and PNG. The three-dimensional graphics processinglibrary is configured to implement three-dimensional graphics drawing, image rendering,composition, layer processing, and the like. The 2D graphics engine is a drawing engine for 2Ddrawing.

[00189] The kernel layer is a layer between hardware and software. The kernel layer includesat least a display driver and the like.

[00190] After the electronic device 100 installs the foregoing application, the internal memory121 in the electronic device 100 stores a layout file of each display interface of the application.When the electronic device 100 detects an operation of running the application, the electronicdevice 100 starts the application, and starts to draw each display interface of the applicationbased on the layout file of the display interface.

[00191] An example in which an electronic device 100 equipped with an Android system runsa clock application is used for description.

[00192] As shown in FIG. 7A, a display interface 701 is a home screen interface displayed bythe electronic device 100 (for example, specifically a mobile phone). In response to an operationof detecting that a user operates an icon 702 of the clock application on the display interface 701,the mobile phone starts the clock application, and draws a home page 703 of the clockapplication. A layout container in which a view 704 on the home page 703 is located has anextension capability. The view 704 changes with the layout container. The home page of theclock application may be understood as the 1st interface displayed after the clock applicationruns.

[00193] It should be further noted that an example in which an application is started to displaya home page is used for description herein. After the application is started, in response to a useroperation, the method provided in this application is also applicable when the mobile phonedisplays another interface (not the home page).

[00194] Specifically, after the clock application is started, the mobile phone creates anActivity corresponding to the application, that is, a main Activity, and then generates aPhoneWindow instance by using an attach() method in the Activity. A DecorView is created inthe PhoneWindow instance, and a screen parameter of the electronic device is obtained todetermine sizes and locations (locations of four vertices, namely, locations of upper, lower, left,and right borders) of the PhoneWindow and the DecorView. Then, an inflate procedure of asetContentView() method of the Window is invoked to read a layout file of the clock application.The layout file includes Views and ViewGroups included in each display interface of the clockapplication (for example, the home page of the clock application), hierarchical structures of theseViews and ViewGroups, and attributes of these Views and ViewGroups. The mobile phoneinvokes a corresponding interface to write each attribute value of these Views and ViewGroups.In addition, a dimension and a location of each ViewGroup and each View in the DecorView aredetermined level by level from a root based on a hierarchical structure of a view tree in thelayout file. In other words, each View in the DecorView calculates a dimension and a location ofthe View based on a dimension constraint transferred by a parent layout container and aconfiguration (that is, a configured attribute value) of the View. Then, the mobile phone draws allViews, to obtain the home page of the clock application.

[00195] It should be noted that the attributes of these Views and ViewGroups herein includean Android native attribute and an attribute related to an adaptive layout capability in thisembodiment of this application. Then, the mobile phone enters a window drawing procedure, andcompletes drawing of the display interface by performing three procedures: measurement(Measure), layout (Layout), and draw (Draw).

[00196] The foregoing measurement is used to calculate an actual size of the View. Startingwith a performMeasure method, a MeasureSpec parameter is included. MeasureSpec indicates a32-bit integer. The most significant two bits indicate a measurement mode (SpecMode), and theleast significant 30 bits indicate a specification dimension (SpecSize) in a measurement mode. Inother words, MeasureSpec is used to describe a manner of measuring this View. The foregoinglayout is used to determine a location of the View in the parent layout container. This isimplemented after the parent layout container obtains a location parameter of a child View,invokes a layout method of the child View, and transfers the location parameter. The foregoingdraw is used to draw a view, starting from a performDraw method. For the layout and drawprocesses, refer to related content in the conventional technology. Details are not describedherein again.

[00197] It should be noted that MeasureSpec of the DecorView is determined based on both awindow dimension and a layout parameter (LayoutParams), and MeasureSpec of a commonView is determined based on both MeasureSpec of a layout container in which the commonView is located (that is, a parent layout container) and LayoutParams.

[00198] In this embodiment of this application, the window dimension is determined based ona screen parameter of the mobile phone. The screen parameter includes a screen specificationparameter, a screen status parameter, and the like. The screen specification includes a dimensionof a screen (for example, a width and a height of the screen). The screen specification determinesa dimension of an area actually used by the mobile phone to display application content. In someexamples, a form of a display also affects a dimension of an area actually used by the electronicdevice to display application content. For example, when the display is a notch screen, an area ofthe notch screen is not used to display application content. For another example, when thedisplay is a curved screen, a curved area at an edge is not used to display application content.The screen status includes whether the screen is in a landscape state or a portrait state. If thescreen is a foldable screen, the screen is in a folded state, a half-folded state, an expanded state,or the like. If the screen supports screen splitting, a dimension of a window displayed by acurrent application. The half-folded state means that, when the foldable screen supports aplurality of times of folding, a part of the screen is in a folded state, and the other part of thescreen is in an expanded state.

[00199] LayoutParams of each of the View and the ViewGroup includes a native attribute ofthe Android system, an attribute related to an adaptive layout capability in this embodiment ofthis application, and the like. Therefore, in a measurement process, the mobile phone performsmeasurement based on the native attributes of the Android system of the View and theViewGroup in the layout file, and further needs to perform measurement based on the attributesrelated to the adaptive layout capabilities of the View and the ViewGroup in the layout file. For aprocess in which the mobile phone performs measurement based on the native attributes of theAndroid system of the View and the ViewGroup in the layout file and a process in which themobile phone performs layout based on the native attributes of the Android system of the Viewand the ViewGroup in the layout file, refer to related content in the conventional technology.Details are not described herein again.

[00200] For each adaptive layout capability extended in this embodiment of this application,the following describes in detail a manner in which a developer designs a layout file including aView or a ViewGroup having an adaptive layout capability and a method for implementingadaptive layout based on a layout file when an electronic device runs an application.

[00201] (1) Extension capability

[00202] When developing an application, after adding dependency of an adaptive layoutattribute package, a developer may set a ViewGroup having an extension capability on a displayinterface. Specifically, when editing a layout file of the display interface, the developer may setan attribute value related to the extension capability of the ViewGroup in the layout file (forexample, an XML file), or may set an attribute value related to the extension capability of theViewGroup in a Java source code file by adding a call interface.

[00203] Table 1 shows an example of an attribute related to the extension capability.Table 1

[00204] It should be noted that, when setting the attribute of the layout container, thedeveloper may enable a general extension capability of the layout container through generalextension capability enablement, and set the default spacing between the child views in thelayout container. A capability of displaying the partial content of the last child view displayed inthe layout container may be further enabled through extended extension capability enablement.The child view that displays partial content may be used to prompt a user that there is a childview that is not displayed or a child view that is not completely displayed in the current layoutcontainer, so that the user can perform a corresponding operation to view the child view that isnot displayed. Further, the dimension threshold and the threshold of the spacing between thechild views in the layout container may be set. Subsequently, when running the application anddrawing the child view, the electronic device determines a quantity of displayed child viewsbased on the dimension of the layout container, the dimension threshold of the child view, thespacing threshold, and the like, adjusts the spacing between the child views, and the like.

[00205] The meaning of each attribute related to the extension capability and an effect ofdisplaying the layout container and the child view are described in detail below with reference tothe accompanying drawings.

[00206] In some embodiments, the developer may set the general extension capability of thelayout container to be enabled, and set the default spacing of the layout container. In this case,the electronic device determines, based on a width of the layout container, a width of eachincluded child view, and the default spacing, a quantity of child views that can be completelydisplayed in the layout container actually.

[00207] For example, it is set that a layout container includes five horizontally arranged childviews: a child view A to a child view E.

[00208] (1) in FIG. 8 is an effect diagram of a layout container displayed by an electronicdevice 1. In this case, width of the layout container displayed by the electronic device 1 ≥ sum ofwidths of child views in the layout container + default spacing * (quantity of child views - 1).Therefore, the layout container on the electronic device 1 may horizontally display all the childviews (the child view A to the child view E), and the child views keep the default spacing. In thiscase, the child view A to the child view E are completely displayed.

[00209] (2) in FIG. 8 is an effect diagram of a layout container displayed by an electronicdevice 2. In this case, width of the layout container displayed by the electronic device 2 < sum ofwidths of child views in the layout container + default spacing * (quantity of child views - 1).Therefore, the layout container on the electronic device 2 cannot completely display all childviews. Therefore, the electronic device 2 may determine, based on the actual width of the layoutcontainer, the width of the child view, and the default spacing, a quantity of child views that canbe completely displayed on the electronic device 2. For example, the layout container on theelectronic device 2 can completely display a maximum of four child views at a time: the childview A to the child view D, and the child views keep the default spacing. In this case, the childview A to the child view D are completely displayed.

[00210] It should be noted that the layout container supports scrolling viewing. In other words,the user may operate the layout container to view another child view that is not currentlydisplayed on a screen. For example, in response to a slide-left operation performed by the useron a location of the layout container on the electronic device 2, the electronic device 2 displaysan interface shown in (3) in FIG. 8, and displays the child view E on the interface. It can belearned that the layout container on the electronic device 2 can also completely display amaximum of four child views in this case.

[00211] In a specific implementation, the extension capability may be set for a layoutcontainer in which an image view, a button view, or the like is located. When a width of thelayout container changes, a quantity of displayed image views or button views may beautomatically determined based on the width of the layout container, so as to meet displayrequirements of electronic devices having different screen dimensions. It can be learned that thegeneral extension capability in this solution can enable electronic devices having different screenparameters to present different display effects based on a same layout setting, reducedevelopment and maintenance workload of developers, and meet display requirements of varioustypes of electronic devices.

[00212] In some other embodiments, the developer may further set the extended extensioncapability of the layout container to be enabled, and set attributes such as the dimensionthreshold and the spacing threshold. In this case, the electronic device determines, based on awidth of the layout container, a width of each child view, and the default spacing, whether thelayout container can completely display all child views. If not all child views are completelydisplayed, the default spacing is reduced until the spacing threshold is reached. If all child viewsstill cannot be completely displayed when the default spacing is reduced to the spacing threshold,a quantity of child views that can be completely displayed actually is determined based on theactual dimension of the layout container, the width of each child view, and the dimensionthreshold.

[00213] For example, it is set that a layout container includes five horizontally arranged childviews: a child view A to a child view E.

[00214] (1) in FIG. 9 is an effect diagram of a layout container displayed by an electronicdevice 1. In this case, width of the layout container displayed by the electronic device 1 ≥ sum ofwidths of child views in the layout container + default spacing * (quantity of child views - 1).Therefore, the layout container on the electronic device 1 may horizontally display all the childviews (the child view A to the child view E), and the child views keep the default spacing. In thiscase, the child view A to the child view E are completely displayed.

[00215] Alternatively, although width of the layout container displayed by the electronicdevice 1 < sum of widths of child views in the layout container + default spacing * (quantity ofchild views - 1), width of the layout container displayed by the electronic device 1 ≥ sum of thewidths of the child views in the layout container + spacing threshold * (quantity of child views -1). The electronic device 1 may also adjust a spacing between child views, so that the layoutcontainer on the electronic device 1 can completely display all child views (the child view A tothe child view E), and the spacing between the child views is greater than or equal to the spacingthreshold.

[00216] (2) in FIG. 9 is an effect diagram of a layout container displayed by an electronicdevice 2. In this case, width of the layout container displayed by the electronic device 2 < sum ofwidths of child views in the layout container + spacing threshold * (quantity of child views - 1).Therefore, the layout container on the electronic device 2 cannot completely display all childviews. In this case, the electronic device needs to display a child view of partial content. Theelectronic device 2 may determine, based on the actual dimension of the layout container, thewidth of each child view, the dimension threshold, and the spacing threshold, a quantity of childviews that can be completely displayed by the layout container. For example, the electronicdevice 2 determines that the layout container can display a maximum of four complete childviews (the child view A to the child view D) and partial content of one child view (partial contentof the child view E) at a time, and the spacing between the child views is greater than or equal tothe spacing threshold.

[00217] (3) in FIG. 9 is an effect diagram of a layout container displayed by an electronicdevice 3. In this case, width of the layout container displayed by the electronic device 3 < sum ofwidths of child views in the layout container + spacing threshold * (quantity of child views - 1).Therefore, the layout container on the electronic device 3 cannot completely display all childviews. In this case, the electronic device needs to display a child view that displays only partialcontent. The electronic device 3 may determine, based on the actual dimension of the layoutcontainer, the width of each child view, the dimension threshold, and the spacing threshold, aquantity of child views that can be displayed by the layout container. For example, the electronicdevice 3 determines that the layout container can display a maximum of three complete childviews (the child view A to the child view C) and partial content of one child view (partial contentof the child view D) at a time, and the spacing between the child views is greater than or equal tothe spacing threshold.

[00218] It should be noted that the layout container supports scrolling viewing. In other words,the user may operate the layout container to view another child view that is not currentlydisplayed on a screen. For example, in response to a slide-left operation performed by the useron a location of the layout container on the electronic device 3, the electronic device 3 displaysan interface shown in (4) in FIG. 9, and displays all content of the child view D and partialcontent of the child view E on the interface.

[00219] It can be learned from the foregoing descriptions that, in this embodiment of thisapplication, a quantity of displayed child views may be adaptively reduced based on a change ofa layout container; and a child view that displays only partial content may also be displayed, anda dimension of the partial content displayed by the child view may keep a fixed value (that is, thedimension threshold). In this way, the child view that displays only partial content may be usedto prompt the user that there is still a child view that is not displayed in the layout container. Inaddition, keeping the dimension threshold as a fixed value can prevent the user from feelingjagged confusion caused because different screen dimensions lead to different dimensions ofchild views that display partial content.

[00220] The following provides an example of a layout file (an XML file). A layout containerwith an extension capability enabled is set in the layout file. In addition, the layout containerincludes four child views: four linear layout containers, and each linear layout container storesone image view and one text view. It should be noted that, because the extension capabilityneeds to support scrolling viewing, the entire layout container having the extension capabilityneeds to be placed in ScrollView, horizontal extension needs to be placed inHorizontalScrollView, and layout_width needs to be set to match_parent. A vertical extensioncapability can be deduced by analogy. / * layout extension example * / <HorizontalScrollViewxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto"android:layout_height="wrap_content" / / set a height of the layout containerandroid:layout_width="match_parent" / / set a width of the layout container / * omit other configurations * / ><hwLayout / * omit other configurations * / android:orientation="horizontal" / / set a layout orientation tohorizontalapp: extension capability enablement="true" / / enable a general extensioncapability of the layout containerapp: extended extension capability enablement="true" / / enable an extendedextension capability of the layout containerapp: dimension threshold="32dp"> / / set a dimension of the last child viewdisplayed in the layout container<LinearLayout / * omit other configurations * / > / / set a child view in the layoutcontainer-linear layout container<ImageView / * omit other configurations * / / / set a child view in thelinear layout container-image viewandroid:background="@drawable / shape_drawable"android:src="@drawable / ic_group_04" / ><TextView / * omit other configurations * / / / set another child view inthe linear layout container-text viewandroid:text="game circle" / >< / LinearLayout><LinearLayout / * omit other configurations * / > / / set another child view in thelayout container-linear layout container<ImageView / * omit other configurations * / / / set a child view in anotherlinear layout container in the layout container-image viewandroid:background="@drawable / shape_drawable"android:src="@drawable / ic_group_05" / ><TextView / * omit other configurations * / / / set another child view inanother linear layout container in the layout container-text viewandroid:text="optical illusion" / >< / LinearLayout><LinearLayout / * omit other configurations * / ><ImageView / * omit other configurations * / android:background="@drawable / shape_drawable"android:src="@drawable / ic_group_01" / ><TextView / * omit other configurations * / android:text="fashion talent" / >< / LinearLayout><LinearLayout / * omit other configurations * / ><ImageView / * omit other configurations * / android:background="@drawable / shape_drawable"android:src="@drawable / ic_group_02" / ><TextView / * omit other configurations * / android:text="travel group" / >< / LinearLayout>< / * omit other configurations * / >< / hwLayout>< / HorizontalScrollView>

[00221] The foregoing embodiment is a solution in which the developer designs an adaptivedisplay interface layout by setting an attribute value related to an extension capability of a Viewor a ViewGroup in a layout file (for example, an XML file). Alternatively, an attribute valuerelated to an extension capability of a View or a ViewGroup may be set in a Java source code fileby adding a call interface.

[00222] Table 2 shows an example of an interface corresponding to the attribute value relatedto the extension capability of the View or the ViewGroup.Table 2

[00223] The meanings of the extension capability are described in detail above. A developermay configure a layout file based on a layout design of each display interface in an applicationwith reference to an extension capability, another adaptive layout capability, and a basic layoutcapability (for example, an Android native attribute), pack the layout file, other source code andresources, and the like of the application into an installation package (for example, an APK file),and release the installation package to an application market. An electronic device downloads theinstallation package from the application market, and installs the application. The followingdescribes in detail a solution of implementing adaptive layout based on the foregoing layout filewhen the electronic device runs the application.

[00224] Specifically, the mobile phone performs a measurement procedure shown in FIG. 10Afor each layout container in the layout file. The method specifically includes the following steps.

[00225] S1001: Read a layout parameter of the layout container.

[00226] The layout parameter of the layout container is read from the layout file (for example,an XML file). The layout parameter of the layout container includes layout information such as ahierarchical relationship of the layout container on the display interface (including a parentlayout container of the layout container, a child view of the layout container, and the like), adimension and a location of the layout container (the dimension and the location are notnecessarily fixed values and may be a constraint), an inner margin of the layout container,dimensions of and spacings between child layout containers included in the layout container, anddimensions of and spacings between views included in the layout container.

[00227] For example, the layout container herein may be a layout container at any layer of thedisplay interface. For example, the layout container herein may be a layout container at an upperlayer of the display interface, for example, the content view in FIG. 1(2). In this case, theelectronic device obtains a screen parameter (including a screen type, a screen dimension, ascreen status, and the like) of the electronic device, to determine a display size (that is, adimension), a display location, and the like of the content view. For another example, the layoutcontainer herein may alternatively be a layout container at a middle layer of the display interface,for example, the view group 3. In this case, the electronic device sequentially determinesdimensions and locations of all layout containers from top to bottom based on the screenparameter of the electronic device and the hierarchical relationship shown in FIG. 1(2), until adisplay size (that is, a dimension), a display location, and the like of the view group 3 aredetermined.

[00228] S1002: Determine whether the layout container enables an extension capability.

[00229] If it is learned, based on the layout file, that the layout container does not enable anextended extension capability and does not enable a general extension capability, a nativemeasurement procedure of the Android system is used for measurement. If the layout containerdoes not enable the extended extension capability but enables the general extension capability,the mobile phone determines a quantity of displayed child views based on the dimension of thelayout container and a default spacing, and arranges the child views. In this case, the child viewsdisplayed by the mobile phone are all completely displayed. If the layout container enables theextended extension capability, step S1003 is performed.

[00230] It should be noted that an attribute value of enabling the extension capability (thegeneral extension capability and the extended extension capability) included in the layout filemay be set by the developer during application development, and the extension capability of thelayout container is fixedly enabled or disabled. In some other embodiments, when developing theapplication, the developer may alternatively set the extension capability of the layout containerto be set by a user. In this case, the user may enable the extension capability of the layoutcontainer, or disable the extension capability of the layout container.

[00231] S1003: Calculate a quantity N1 of child views that can be completely displayed bythe layout container.

[00232] Specifically, the quantity N1 of child views that can be displayed is preliminarilydetermined based on the dimension of the layout container, the dimension of each child view, thedefault spacing, and a dimension threshold. For example, N1 (rounded) = (width of the layoutcontainer - dimension threshold - inner margin of the layout container) / (width of the child view+ default spacing).

[00233] S1004: Calculate a remaining space of the layout container based on N1.

[00234] For example, remaining space of the layout container (±double-precision type) =(width of the layout container - dimension threshold - inner margin of the layout container) - N1* (width of the child view + default spacing).

[00235] S1005: Calculate a variation ΔM of a spacing between child views based on N1 andthe remaining space of the layout container.

[00236] For example, the variation ΔM of the spacing between child views(±double-precision type) = remaining space of the layout container / N1.

[00237] S1006: Calculate a spacing M based on the variation ΔM of the spacing betweenchild views and the default spacing.

[00238] For example, spacing M (±double-precision type) = variation ΔM of the spacingbetween child views + default spacing.

[00239] S1007: Determine whether the spacing M is greater than or equal to a spacingthreshold that is set in the layout file.

[00240] If the spacing M is less than the spacing threshold, the quantity N1 of child views thatcan be displayed is decreased by one, and then the spacing between child views continues to beadjusted, that is, step S1008 is performed. If the spacing M is greater than or equal to the spacingthreshold, the current child views may be arranged based on the spacing, and step S1009 isperformed.

[00241] S1008: N1 = N1 - 1, and then perform step S1004.

[00242] S1009: Calculate a quantity Na of child views on which spacing widening needs to beperformed and a quantity Nb of child views on which spacing narrowing needs to be performed.Na + Nb = N1.

[00243] S1010: Update spacings between the N1 child views.

[00244] It should be noted that, in this embodiment, the remaining space in the layoutcontainer excluding a child view display space, a dimension threshold display space, and aninner margin space reserved in the layout container needs to be evenly allocated as the spacingbetween child views (including a child view that displays partial content). Because the electronicdevice performs display by using a pixel as a unit, the remaining space cannot be generallyevenly divided strictly. Therefore, after the spacing that meets a condition (not less than thespacing threshold) is obtained, spacings between all child views may be further fine-tuned, sothat the spacings between the child views completely occupy the remaining space. For example,the obtained spacing that meets the condition is rounded up by using a pixel as a unit, to obtain awidened spacing. In this case, quantity Na of child views on which spacing widening isperformed = decimal part of the spacing * N1. The obtained spacing that meets the condition isrounded down by using a pixel as a unit, to obtain a narrowed spacing. In this case, quantity Nbof child views on which spacing narrowing is performed = N1 - Na.

[00245] For example, a quantity, obtained through calculation according to the foregoing steps,of child views that need to be displayed is 5, and a spacing is 3.2 pixels. In this case, a widenedspacing obtained after the spacing is rounded up is 4. Quantity of child views on which spacingwidening needs to be performed = (3.2 - 3) * 5 = 1, that is, a spacing with one of the child viewsneeds to be determined as 4 pixels. A widened spacing obtained after the spacing is roundeddown is 3. Quantity of child views on which spacing narrowing needs to be performed = 5 - 1 =4, that is, a spacing with each of the four child views is determined as 3 pixels. Specifically, amanner of determining child views on which spacing widening needs to be performed and childviews on which spacing narrowing needs to be performed is not specifically limited in thisembodiment of this application. Certainly, the spacing between child views in the layoutcontainer may alternatively be adjusted by using another method.

[00246] In this way, values of the spacings between the child views in the layout container areapproximately equal, and an error is kept within ±1 pixel.

[00247] It should be noted that, in this embodiment, the layout container displays partialcontent of the (N1+1)th child view.

[00248] It should be further noted that an example in which widths of the child views includedin the layout container are equal is used for description herein. If the widths of the child viewsare not equal, the extended extension capability may not be enabled by default. In other words,the layout container does not display a child view having only partial content. Specifically, theelectronic device may need to perform calculation based on an order of arranging all the childviews included in the layout container, the width of each child view, and the default spacing, todetermine a quantity of child views that can be completely displayed by the layout container; andarrange, based on the default spacing, the child views that can be completely displayed.

[00249] It can be understood that, when electronic devices (for example, a mobile phone and atablet computer) having different screen dimensions use a same layout file (including a layoutcontainer provided with an extension capability), according to the measurement procedure inFIG. 10A, application interfaces finally drawn may present different layout effects.

[00250] For example, a screen width of the mobile phone is 720 pixels, and a screen width ofthe tablet computer is 1280 pixels. Both the mobile phone and the tablet computer use a sameinstallation package to install the application market. A layout file corresponding to a home pageof the application market includes a layout container configured to display a high-qualityapplication, and the layout container enables an extended extension capability. In addition, thelayout container includes 10 horizontally arranged child views, and each child view correspondsto one application icon. A width of each child view is 120 pixels, a default spacing is 40 pixels,and a dimension threshold (that is, a width of a child view that is not completely displayed) is 80pixels. In addition, a width of the layout container is equal to the device screen width, and aninner margin is 0 pixels.

[00251] In this case, when the mobile phone draws the home page of the application marketand performs the measurement procedure in FIG. 10A, a quantity of child views that can bedisplayed by the mobile phone is calculated as follows: N1 = (width of the layout container -dimension threshold - inner margin of the layout container) / (width of the child view + defaultspacing) = (720 - 80 - 0) / (120 + 40) = 4. In other words, the mobile phone can completelydisplay four child views and incompletely display one child view. The mobile phone displays aninterface 101 shown in FIG. 10B(1), and a layout container 102 includes four completelydisplayed application icons and one incompletely displayed application icon.

[00252] When the tablet computer draws the home page of the application market andperforms the measurement procedure in FIG. 10A, a quantity of child views that can bedisplayed by the tablet computer is calculated as follows: N1 = (width of the layout container -dimension threshold - inner margin of the layout container) / (width of the child view + defaultspacing) = (1280 - 80 - 0) / (120 + 40) = 7.5. In other words, the tablet computer can completelydisplay seven child views and incompletely display one child view. The tablet computer displaysan interface 103 shown in FIG. 10B(2), and a layout container 104 includes seven completelydisplayed application icons and one incompletely displayed application icon.

[00253] FIG. 11 is another schematic diagram of an adaptive application interface layoutmethod according to an embodiment of this application. In an application development phase, adeveloper may set an attribute related to an extension capability in a layout file such as an XMLfile. For example, the developer enables an extension capability, sets a default spacing, sets aspacing threshold, enables an extended extension capability, and sets a dimension threshold.Subsequently, the developer packs the layout file, other application code and resources, and thelike into an installation package, and releases the installation package to an application market.Then, a user may download the installation package from the application market by using anelectronic device, and install the application. When the electronic device runs the application, alayout module in the electronic device parses the attribute related to the extension capabilityfrom the layout file, to obtain an attribute value related to the extension capability, and sends theattribute value to an extension module in the electronic device. Then, the layout module performsmeasurement, and starts an extension capability process. In other words, the extension modulecalculates a parameter of a related view such as a dimension of the view based on the attributevalue related to the extension capability. The layout module performs layout based on an updatedparameter of the view, to obtain a location of the view on a specific display interface of theapplication. Finally, the electronic device may draw and display the specific display interface. Ina specific example, the layout module may be a measurement module and a layout module in anative view system of an Android system. The extension module may be a newly added functionmodule in the measurement module in the view system, and may perform related steps in FIG.10A.

[00254] (2) Proportion capability

[00255] When developing an application, after adding dependency of an adaptive layoutattribute package, a developer may set a layout container (that is, a ViewGroup) having aproportion capability on a display interface. Specifically, when editing a layout file of the displayinterface, the developer may set an attribute value related to the proportion capability of theViewGroup in the layout file (for example, an XML file), or may set an attribute value related tothe proportion capability of the ViewGroup in a Java source code file by adding a call interface.

[00256] Table 3 shows an example of an attribute related to the proportion capability.Table 3

[00257] It should be noted that, when setting the attribute of the layout container, thedeveloper may enable the proportion capability of the layout container through proportioncapability enablement, and set the proportion for each child view in the layout container (that is,a View or a ViewGroup stored in the layout container). Subsequently, when running theapplication and drawing each child view in the layout container, the electronic device draws thechild view in the layout container based on a dimension of the layout container and theproportion of the child view.

[00258] The meaning of each attribute related to the proportion capability and an effect ofdisplaying the layout container and the child view are described in detail below with reference tothe accompanying drawings.

[00259] As shown in (1) in FIG. 12, a proportion of the child view to the layout container in ahorizontal orientation is a ratio of a width (X) of the child view to a total width (Y) of the layoutcontainer, that is, X / Y, and a proportion of the child view to the layout container in a verticalorientation is a ratio of a height (R) of the child view to a total height (T) of the layout container,that is, R / T.

[00260] When an attribute of the layout container is set, an attribute value of proportioncapability enablement is set to "true". Then, a proportion is set to M (M is a fraction) for thechild view. A specific meaning of the proportion M (a horizontal proportion or a verticalproportion) may be determined based on a layout orientation of the layout container.

[00261] For example, if the layout orientation of the layout container is the horizontalorientation (or referred to as a horizontal direction), the proportion M represents a proportion ofthe child view in the horizontal orientation, that is, a fraction of the width of the child view to thetotal width of the layout container. In this case, when the width of the layout container changes,the width of the child view in the layout container is scaled, until a scaled width of the child viewaccounts for M of the total width of the layout container. However, the height of the child viewdoes not change with the height of the layout container. For example, compared with adimension of the layout container shown in (1) in FIG. 12, the width of the layout containershown in (2) in FIG. 12 changes (changes to Y'), but the height remains unchanged. In this case,the width of the child view correspondingly changes to X', where X' = M * Y'; and the height ofthe child view remains unchanged and is still R. For another example, compared with thedimension of the layout container shown in (1) in FIG. 12, the width of the layout containershown in (3) in FIG. 12 changes (changes to X'), and the height also changes (changes to T'). Inthis case, the width of the child view correspondingly changes to X', where X' = M * Y'; and theheight of the child view remains unchanged and is still R. It should be noted that, herein, a layoutparameter for changing the height of the child view is not set in the layout file. In conclusion, theproportion capability is applied to only a dimension of the child view in the layout orientation ofthe layout container (the layout orientation in this example is the horizontal orientation), but isnot applied to a dimension of the child view in another orientation (for example, the verticalorientation in this example).

[00262] If the layout orientation of the layout container is the vertical orientation (or referredto as a vertical direction), the proportion M represents a proportion of the child view in thevertical orientation, that is, a fraction of the height of the child view to the total height of thelayout container. In this case, when the height of the layout container changes, the height of thechild view in the layout container is scaled, until a scaled height of the child view accounts for Mof the total width of the layout container. However, the width of the child view does not changewith the width of the layout container. For example, compared with the dimension of the layoutcontainer shown in (1) in FIG. 12, the height of the layout container shown in (4) in FIG. 12changes (changes to T'), but the width remains unchanged. In this case, the height of the childview correspondingly changes to R', where R' = M * T'; and the width of the child view remainsunchanged and is still X. For another example, compared with the dimension of the layoutcontainer shown in (1) in FIG. 12, the height of the layout container shown in (5) in FIG. 12changes (changes to T'), and the width also changes (changes to Y'). In this case, the height ofthe child view correspondingly changes to R', where R' = M * T'; and the width of the child viewremains unchanged and is still X. It should be noted that, herein, a layout parameter for changingthe width of the child view is not set in the layout file. In conclusion, the proportion capability isapplied to only a dimension of the child view in the layout orientation of the layout container(the layout orientation in this example is the vertical orientation), but is not applied to adimension of the child view in another orientation (for example, the horizontal orientation in thisexample).

[00263] It should be noted that an example in which only one parameter, that is, theproportion M, is set is used above for description. In this example, a specific meaning of theproportion M (a horizontal proportion or a vertical proportion) may be determined based on alayout orientation of the layout container In some other examples, different parameters mayalternatively be set to represent a proportion (for example, a proportion P) in the horizontalorientation and a proportion (for example, a proportion Q) in the vertical orientation. This is notlimited in this embodiment of this application.

[00264] For example, the developer may set the proportion of the child view to 50%. Asshown in (1) in FIG. 12, a dimension of the layout container on an electronic device 1 is 1080 *540 (width * height, in a unit of pixel), and a dimension of the child view is 540 * 270. In thiscase, both the proportions of the child view in the horizontal orientation and the verticalorientation reach 50%.

[00265] In some examples, the layout orientation of the layout container is set to horizontal.As shown in (2) in FIG. 12, a dimension of the layout container on an electronic device 2 is 2160* 540 (in a unit of pixel). In this case, the height of the layout container in the electronic device 2is the same as that of the layout container in the electronic device 1, but the width is increased.Therefore, the child view is scaled based on the horizontal proportion (50%), and the dimensionof the child view is calculated as 1080 * 270 (in a unit of pixel). As shown in (3) in FIG. 12, adimension of the layout container on an electronic device 3 is 2160 * 1080 (in a unit of pixel). Inthis case, both the width and the height of the layout container in the electronic device 3 aregreater than those of the layout container in the electronic device 1. Therefore, the child view isscaled based on the horizontal proportion (50%), and the dimension of the child view iscalculated as 1080 * 270 (in a unit of pixel).

[00266] In some other examples, the layout orientation of the layout container is set to vertical.As shown in (4) in FIG. 12, a dimension of the layout container on an electronic device 4 is 1080* 1080 (in a unit of pixel). In this case, the height of the layout container in the electronic device4 is the same as that of the layout container in the electronic device 1, but the height is increased.Therefore, the child view is scaled based on the vertical proportion (50%), and the dimension ofthe child view is calculated as 540 * 540 (in a unit of pixel). As shown in (5) in FIG. 12, adimension of the layout container on an electronic device 5 is 2160 * 1080 (in a unit of pixel). Inthis case, the height of the layout container in the electronic device 5 is greater than those of thelayout container in the electronic device 1. Therefore, the child view is scaled based on thevertical proportion (50%), and the dimension of the child view is calculated as 540 * 540 (in aunit of pixel).

[00267] In a specific implementation, a proportion capability may be set for a layout containerin which a text view, a button view, an image view, or the like is located. When a width or aheight of the layout container changes, a width or a height of the text view, the button view, orthe image view may automatically and adaptively change based on the width or the height of thelayout container, so as to meet display requirements of electronic devices having different screendimensions. It can be learned that the proportion capability in this solution can enable electronicdevices having different screen parameters to present different display effects based on a samelayout setting, reduce development and maintenance workload of developers, and meet displayrequirements of various types of electronic devices.

[00268] The foregoing embodiment is described by using one child view in the layoutcontainer. When the layout container includes a plurality of child views, a proportion may be setfor each of the plurality of child views, or a proportion may be set for some of the plurality ofchild views.

[00269] In some embodiments, the proportion is set for each of the plurality child views. For amethod for scaling each child view in a specified orientation, refer to the method for scaling achild view in a specified orientation in the foregoing embodiment. Details are not describedherein again. It should be noted that, if a sum of proportions of all child views is greater than100%, truncation occurs, that is, not all the child views can be displayed in the layout container.In some examples, when the developer sets the proportions of the child views, and the sum of thespecified proportions is greater than 100%, the developer may be prompted to changeproportions of some child views, or the developer is prompted to set another capability of thelayout container, for example, a hiding capability. In some other examples, when an electronicdevice displays the layout container, a user may be prompted to perform interface adjustment. Ifthe sum of the proportions of all the child views is less than 100%, blank-leaving occurs. In someother examples, the user may be prompted to select or increase by default a spacing betweenchild views.

[00270] In some other embodiments, for a case in which proportions are set for some childviews and no proportion is set for some child views in the layout container, a dimension, in aspecified orientation, of each child view for which a proportion is set may be first calculated, andthen a remaining space in the layout container is allocated to child views for which no proportionis set. For example, after the dimension, in the specified orientation, of each child view for whicha proportion is set is determined, the remaining space in the layout container is evenly allocatedto the child views for which no proportion is set.

[00271] For example, as shown in (1) in FIG. 13, a layout container includes three child views:a child view 1, a child view 2, and a child view 3. A layout orientation of the layout container is ahorizontal orientation.

[00272] As shown in (2) in FIG. 13, if a proportion, for example, 20%, is set for each of thechild view 1 to the child view 3, when a width of the layout container changes, the proportion ofeach of the child view 1 to the child view 3 to the width of the layout container remains at 20%.

[00273] As shown in (3) in FIG. 13, if a proportion, for example, 20%, is set for the childview 1, but no proportion is set for the child view 2 and the child view 3, when the width of thelayout container changes, the proportion of the child view 1 to the width of the layout containerfirst remains at 20%. Then, a remaining space (80%) in the layout container is evenly allocatedto the child view 2 and the child view 3, that is, the child view 2 and the child view 3 eachoccupy 40% of the width of the layout container. It may be noted that, in this example,proportions of the child view 1, the child view 2, and the child view 3 are exactly equal to 100%.In other words, there is no spacing between child views. In some examples, when the developersets proportions of child views, and a sum of the specified proportions is equal to 100%, thedeveloper may be prompted that there is no spacing between child views. If the developer wantsto have a spacing between child views, the developer may set a sum of child views to be lessthan 100%.

[00274] The following describes application of a proportion capability of a layout containerwith reference to a case in which an interface of a layout container with a proportion capabilityenabled is nested in another layout container with a proportion capability enabled.

[00275] As shown in an interface shown in (1) in FIG. 14, a layout container 1400 includes achild view 1401 and a child view 1402. The layout container 1400 enables a proportioncapability, and a layout orientation of the layout container 1400 is a vertical orientation. Aproportion A (for example, 60%) of the child view 1401 is set. In this case, the proportion of thechild view 1401 is a vertical proportion. In other words, a height of the child view 1401 changeswith a height of the layout container 1400, and a fraction of the height of the child view 1401 tothe height of the layout container 1400 remains as the proportion A.

[00276] Each of the child view 1401 and the child view 1402 is essentially one ViewGroup,that is, one layout container, which is also referred to as a layout container view. The child view1402 includes play views such as "Previous", "Play", "Next", and "More". The child view 1401also enables a proportion capability, and a layout orientation of the child view 1401 is ahorizontal orientation. The child view 1401 includes a child view 1403 (one image view) and achild view 1404 (a plurality of text views). A proportion B (for example, 30%) of the child view1403 is set. In this case, the proportion of the child view 1403 is a horizontal proportion. In otherwords, a width of the child view 1403 changes with a width of the layout container 1401, and afraction of the width of the child view 1403 to the layout width of the layout container 1401remains as the proportion B.

[00277] It can be learned that a height of the child view 1403 changes with the height of thelayout container 1400, the width of the child view 1403 changes with a width of the child view1401, and the width of the child view 1401 changes with the width of the layout container 1400.Therefore, the width and the height of the child view 1403 change with the width and the heightof the layout container 1400, but an aspect ratio of the child view 1403 may change. In otherwords, a method for changing the width and the height of the child view 1403 herein is differentfrom a method in which a child view keeps an aspect ratio for scaling in a scaling capability, sothat more display requirements of an application interface can be met.

[00278] For example, as shown in (1) in FIG. 14, if a dimension of the layout container 1400on an electronic device 1 is 1080 * 540 (width * height, in a unit of pixel), a dimension of thechild view 1401 (that is, a child layout container) is 1080 * 324 (in a unit of pixel) (height of thechild view 1401 = (540 * 60%) pixels); a dimension of the child view 1402 is 1080 * 216 (in aunit of pixel) (height of the child view 1402 = (540 - 324) pixels); a dimension of the child view1403 is 324 * 324 (in a unit of pixel) (width of the child view 1403 = (1080 * 30%) pixels); anda dimension of the child view 1404 is 756 * 324 (in a unit of pixel).

[00279] As shown in (2) in FIG. 14, if a dimension of the layout container 1400 on anelectronic device 2 is 1280 * 540 (width * height, in a unit of pixel), a dimension of the childview 1401 (that is, a child layout container) is 1280 * 324 (in a unit of pixel) (height of the childview 1401 = (540 * 60%) pixels); a dimension of the child view 1402 is 1280 * 216 (in a unit ofpixel) (height of the child view 1402 = (540 - 324) pixels); a dimension of the child view 1403 is384 * 324 (in a unit of pixel) (width of the child view 1403 = (1280 * 30%) pixels); and adimension of the child view 1404 is 896 * 324 (in a unit of pixel).

[00280] As shown in (3) in FIG. 14, if a dimension of the layout container 1400 on anelectronic device 3 is 1080 * 640 (width * height, in a unit of pixel), a dimension of the childview 1401 (that is, a child layout container) is 1080 * 384 (in a unit of pixel) (height of the childview 1401 = (640 * 60%) pixels); a dimension of the child view 1402 is 1080 * 256 (in a unit ofpixel) (height of the child view 1402 = (640 - 384) pixels); a dimension of the child view 1403 is324 * 384 (in a unit of pixel) (width of the child view 1403 = (1080 * 30%) pixels); and adimension of the child view 1404 is 756 * 384 (in a unit of pixel).

[00281] As shown in (4) in FIG. 14, if a dimension of the layout container 1400 on anelectronic device 4 is 1280 * 640 (width * height, in a unit of pixel), a dimension of the childview 1401 (that is, a child layout container) is 1280 * 384 (in a unit of pixel) (height of the childview 1401 = (640 * 60%) pixels); a dimension of the child view 1402 is 1280 * 256 (in a unit ofpixel) (height of the child view 1402 = (640 - 384) pixels); a dimension of the child view 1403 is384 * 384 (in a unit of pixel) (width of the child view 1403 = (1280 * 30%) pixels); and adimension of the child view 1404 is 896 * 384 (in a unit of pixel).

[00282] The following provides an example of a layout file (an XML file) of the layoutcontainer 1400.<hwLayout / / set a layout parameter of the layout container 1400xmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto" / * omit other configurations * / app: proportion enablement="true" / / enable a proportion capability of thelayout container 1400android:orientation="vertical"> / / the layout orientation of the layout container1400 is the vertical orientation, which means that a proportion that is set for a child view in thelayout container is a vertical proportion<hwLayout / / set a layout parameter of the child view 1401 inthe layout container 1400 / * omit other configurations * / app: proportion enablement="true" / / enable a proportioncapability of the child view 1401android:orientation="horizontal" / / set the layout orientation of the childview 1401 to the horizontal orientation, which means that a proportion that is set for a child viewnested in the child view 1401 is a horizontal proportionapp: proportion="140%" > / / set a vertical proportion of thechild view 1401<ImageView / / set a layout parameter of the child view 1403nested in the child view 1401 / * omit other configurations * / app: proportion="30%" / > / / set a horizontal proportion of the childview 1403<hwLayout / / set a layout parameter of the child view 1404 nested in thechild view 1401 / * omit other configurations * / app: proportion="70%" > / / set a horizontal proportion of another childview 1404 nested in the child view 1401, or set no horizontal proportion of the child viewbecause the child view 1401 includes only two horizontally arranged child views<TextView / / set a layout parameter of the child view 1403nested in the child view 1401 / * omit other configurations * / android:text="song name" / ><TextView / * omit other configurations * / android:text="singer name" / >< / hwLayout>< / hwLayout><hwLayout / / set a layout parameter of the child view 1402in the layout container 1400 / * omit other configurations * / ><ImageView / * omit other configurations * / / ><ImageView / * omit other configurations * / / ><ImageView / * omit other configurations * / / >< / hwLayout>< / hwLayout>

[00283] The foregoing embodiment is a solution in which the developer designs an adaptivedisplay interface layout by setting an attribute value related to a proportion capability of a Viewor a ViewGroup in a layout file (for example, an XML file). Alternatively, an attribute valuerelated to a proportion capability of a View or a ViewGroup may be set in a Java source code fileby adding a call interface.

[00284] Table 4 shows an example of an interface corresponding to the attribute value relatedto the proportion capability of the View or the ViewGroup.Table 4

[00285] The meanings of the proportion capability are described in detail above. A developermay configure a layout file based on a layout design of each display interface in an applicationwith reference to a proportion capability, another adaptive layout capability, and a basic layoutcapability (for example, an Android native attribute), pack the layout file, other source code andresources, and the like of the application into an installation package (for example, an APK file),and release the installation package to an application market. An electronic device downloads theinstallation package from the application market, and installs the application. The followingdescribes in detail a solution of implementing adaptive layout based on the foregoing layout filewhen the electronic device runs the application.

[00286] Specifically, the mobile phone performs a measurement procedure shown in FIG.15A(1) and FIG. 15A(2) for each layout container in the layout file. The method specificallyincludes the following steps.

[00287] S1501: Determine that the layout container enables a proportion capability, and obtaina layout parameter of a child view in the layout container.

[00288] It is determined, based on a layout parameter of the layout container in the layout file,whether the layout container enables the proportion capability and whether a layout orientationof the layout container is a horizontal orientation or a vertical orientation. Further, a child viewincluded in the layout container and a configured proportion of the child view are obtained. If thelayout orientation of the layout container is the horizontal orientation, the proportion of the childview is a horizontal proportion. If the layout orientation of the layout container is the verticalorientation, the proportion of the child view is a vertical proportion.

[00289] In this case, remaining space of the layout container in the layout orientation =width / height of the layout container - left / right / upper / lower inner margin. Specifically, if thelayout orientation of the layout container is the horizontal orientation, remaining width of thelayout container = width of the layout container - left and right inner margins of the layoutcontainer. If the layout orientation of the layout container is the vertical orientation, remainingheight of the layout container = height of the layout container - upper and lower inner margins ofthe layout container.

[00290] S1502: Determine whether a proportion of a current child view is greater than 0; andif yes, perform step S1503; or if no, perform step S1505.

[00291] S1503: Determine a dimension of the current child view based on the layoutorientation of the layout container.

[00292] The layout orientation is an orientation in which the layout container arranges childviews, including the horizontal orientation and the vertical orientation. If the layout orientationof the layout container is the horizontal orientation, width of the current child view = proportion* width of the layout container. If the layout orientation of the layout container is the verticalorientation, height of the current child view = proportion * height of the layout container.

[00293] S1504: Update the remaining space of the layout container.

[00294] If the layout orientation of the layout container is the horizontal orientation,remaining width of the layout container = width of the layout container - width of the currentchild view - left and right inner margins. If the layout orientation of the layout container is thevertical orientation, remaining height of the layout container = height of the layout container -height of the current child view - upper and lower inner margins.

[00295] Then, step S1506 is performed.

[00296] S1505: Record that the current child view is a child view for which no proportion isset or an invalid proportion is set.

[00297] S1506: Determine whether all child views in the layout container are traversed; and ifyes, perform step S1507; or if no, perform step S1510.

[00298] S1507: Determine whether the remaining space of the layout container is greater than0; and if yes, perform step S1508; otherwise, perform step S1509.

[00299] S1508: Evenly allocate the remaining space of the layout container to child views forwhich no proportion is set or an invalid proportion is set.

[00300] The measurement ends.

[00301] S1509: Set a dimension of a child view for which no proportion is set or an invalidproportion is set to 0.

[00302] The measurement ends.

[00303] S1510: Determine a next child view as a current child view. Then, step S1502 isperformed.

[00304] This provides a method for measuring a layout container including a child view forwhich a proportion is set and a child view for which no proportion is set. It can be understoodthat an example in which the remaining space of the layout container in the layout orientation(total width / total height of the layout container - left and right / upper and lower inner margins -sum of widths / heights of child views for which a proportion is set) is evenly allocated to childviews for which no proportion is set is used herein for description. Certainly, a manner ofallocating, according to another rule, the remaining space in the layout orientation to child viewsfor which no proportion is set is not limited in this embodiment of this application.

[00305] It can be understood that, when electronic devices (for example, a mobile phone and atablet computer) having different screen dimensions use a same layout file (including a layoutcontainer provided with a proportion capability), according to the measurement procedure in FIG.15A(1) and FIG. 15A(2), application interfaces finally drawn may present different layouteffects.

[00306] For example, a screen width of the mobile phone is 720 pixels, and a screen width ofthe tablet computer is 1280 pixels. Both the mobile phone and the tablet computer use a sameinstallation package to install a music application. A layout file corresponding to a home page ofthe music application includes a layout container configured to display a ranking, and the layoutcontainer enables a proportion capability. The layout container includes a child view 1(configured to display a poster of a ranking 1), a child layout container (configured to displayinformation about the top three songs), and a child view 2 (configured to notify a user that thereare other rankings subsequently) that are horizontally arranged. A proportion of the child view 1is set to 30%, no proportion is set for the child layout container, and a proportion of the childview 2 is set to 15%.

[00307] Therefore, when the mobile phone draws the home page of the music application, andperforms the measurement procedure in FIG. 15A(1) and FIG. 15A(2) for the layout containerconfigured to display a ranking, the mobile phone performs the following calculation: width ofthe layout container = screen width of the mobile phone = 720 pixels. In this case, width of thechild view 1 = width of the layout container * proportion of the child view 1 = 720 * 30% = 216pixels, width of the child view 2 = width of the layout container * proportion of the child view 2= 720 * 15% = 108 pixels, and width of the child layout container = width of the layout container- sum of the determined widths of the child views = 720 - (216 + 108) = 396 pixels. The mobilephone displays an interface 151 shown in FIG. 15B(1). A width of a child view 153 in the layoutcontainer 152 is 216 pixels, a width of a child view 155 is 108 pixels, and a width of a childlayout container 154 is 396 pixels.

[00308] When the tablet computer draws the home page of the music application, andperforms the measurement procedure in FIG. 15A(1) and FIG. 15A(2) for the layout containerconfigured to display a ranking, the tablet computer performs the following calculation: width ofthe layout container = screen width of the tablet computer = 1280 pixels. In this case, width ofthe child view 1 = width of the layout container * proportion of the child view 1 = 1280 * 30% =384 pixels, width of the child view 2 = width of the layout container * proportion of the childview 2 = 1280 * 15% = 192 pixels, and width of the child layout container = 1280 - 384 - 192 =704 pixels. The tablet computer displays an interface 156 shown in FIG. 15B(2). A width of achild view 158 in the layout container 156 is 384 pixels, a width of a child view 150 is 192 pixels,and a width of a child layout container 159 is 704 pixels.

[00309] FIG. 16 is another schematic diagram of an adaptive application interface layoutmethod according to an embodiment of this application. In an application development phase, adeveloper may set an attribute related to a proportion capability in a layout file such as an XMLfile. For example, the developer enables a proportion capability, sets a layout orientation of alayout container, and sets a proportion of a child view. Subsequently, the developer packs thelayout file, other application code and resources, and the like into an installation package, andreleases the installation package to an application market. Then, a user may download theinstallation package from the application market by using an electronic device, and install theapplication. When the electronic device runs the application, a layout module in the electronicdevice parses the attribute related to the proportion capability from the layout file, to obtain anattribute value related to the proportion capability, and sends the attribute value to a proportionmodule in the electronic device. Then, the layout module performs measurement, and starts aproportion capability process. In other words, the proportion module calculates a parameter of arelated view such as a dimension of the view based on the attribute value related to theproportion capability. The layout module performs layout based on an updated parameter of theview, to obtain a location of the view on a specific display interface of the application. Finally,the electronic device may draw and display the specific display interface. In a specific example,the proportion module may perform related steps in FIG. 15A(1) and FIG. 15A(2). The layoutmodule may be a measurement module and a layout module in a native view system of anAndroid system. The proportion module is a newly added function module in the measurementmodule in the native view system of the Android system in this application.

[00310] (3) Equalization capability

[00311] When developing an application, after adding dependency of an adaptive layoutattribute package, a developer may set a layout container (that is, a ViewGroup) having anequalization capability on a display interface. Specifically, when editing a layout file of thedisplay interface, the developer may set an attribute value related to the equalization capability ofthe ViewGroup in the layout file (for example, an XML file), or may set an attribute value relatedto the equalization capability of the ViewGroup in a Java source code file by adding a callinterface.

[00312] Table 5 shows an example of an attribute related to the equalization capability.Table 5

[00313] It should be noted that, when setting the attribute of the layout container, thedeveloper may enable the equalization capability of the layout container through equalizationcapability enablement, may further set the equalization type, and set the spacing threshold A andthe spacing threshold B. Subsequently, when running the application and drawing each childview in the layout container, the electronic device determines a spacing between child viewsbased on a dimension of the layout container and a dimension of the child view, and draws thechild view in the layout container.

[00314] The meaning of each attribute related to the equalization capability and an effect ofdisplaying the layout container and the child view are described in detail below with reference tothe accompanying drawings.

[00315] For example, the equalization capability may include a first-type equalizationcapability and a second-type equalization capability.

[00316] The equalization capability may be understood as that a remaining space obtained bysubtracting a space occupied by each child view from an available space of the layout containeris evenly allocated as a spacing between child views in a specified orientation. When no innermargin is set for the layout container, available space of the layout container = dimension of thelayout container. When an inner margin is set for the layout container, available space of thelayout container = dimension of the layout container - inner margin.

[00317] The foregoing first-type equalization capability means that no spacing needs to beallocated to a side that is of the 1st child view and that is closest to the layout container in alayout orientation and a side that is of the last child view and that is closest to the layoutcontainer in the layout orientation.

[00318] For example, the layout orientation of the layout container is a horizontal orientation(or referred to as a horizontal direction), and the first-type equalization capability of the layoutcontainer is enabled. In some examples, when no inner margin is set for the layout container, anavailable width of the layout container is a width of the layout container. A location relationshipbetween child views displayed in the layout container may be shown in (1) in FIG. 17. A leftedge of the 1st child view coincides with a left edge of the layout container, a right edge of thelast child view in the layout container coincides with a right edge of the layout container, andspacings between adjacent child views are equal or substantially equal. In some other examples,the layout container sets an inner margin in the layout orientation, for example, a left innermargin (or referred to as a left inner margin or a left inner margin) and a right inner margin (orreferred to as a right inner margin or a right inner margin). In this case, available width of thelayout container = width of the layout container - left inner margin - right inner margin.Therefore, a location relationship between child views displayed in the layout container may beshown in (2) in FIG. 17. A distance between a left edge of the 1st child view and a left edge of thelayout container is equal to a left inner margin of the layout container, a distance between a rightedge of the last child view in the layout container and a right edge of the layout container isequal to a right inner margin of the layout container, and spacings between adjacent child viewsare equal or substantially equal.

[00319] For another example, the layout orientation of the layout container is a verticalorientation (or referred to as a vertical direction), and the first-type equalization capability of thelayout container is enabled. In some examples, when no inner margin is set for the layoutcontainer, an available height of the layout container is a height of the layout container. Alocation relationship between child views displayed in the layout container may be shown in (1)in FIG. 18. An upper edge of the 1st child view coincides with an upper edge of the layoutcontainer, a lower edge of the last child view in the layout container coincides with a lower edgeof the layout container, and spacings between adjacent child views are equal or substantiallyequal. In some other examples, the layout container sets an inner margin in the layout orientation,for example, an upper inner margin (or referred to as an upper inner margin or an upper innermargin) and a lower inner margin (or referred to as a lower inner margin or a lower inner margin).In this case, available height of the layout container = height of the layout container - upperinner margin - lower inner margin. Therefore, a location relationship between child viewsdisplayed in the layout container may be shown in (2) in FIG. 18. A distance between an upperedge of the 1st child view and an upper edge of the layout container is equal to an upper innermargin of the layout container, a distance between a lower edge of the last child view in thelayout container and a lower edge of the layout container is equal to a lower inner margin of thelayout container, and spacings between adjacent child views are equal or substantially equal.

[00320] The foregoing second-type equalization capability means that a spacing needs to beallocated to a side that is of the 1st child view and that is closest to the layout container in alayout orientation and a side that is of the last child view and that is closest to the layoutcontainer in the layout orientation.

[00321] For example, the layout orientation of the layout container is a horizontal orientation,and the second-type equalization capability of the layout container is enabled. In some examples,when no inner margin is set for the layout container, an available width of the layout container isa width of the layout container. A location relationship between child views displayed in thelayout container may be shown in (3) in FIG. 17. A spacing between a left edge of the 1st childview and a left edge of the layout container, a spacing between a right edge of the last child viewin the layout container and a right edge of the layout container, and a spacing between adjacentchild views are equal or substantially equal. In some other examples, the layout container sets aninner margin in the layout orientation, for example, a left inner margin and a right inner margin.In this case, available width of the layout container = width of the layout container - left innermargin - right inner margin. Therefore, a location relationship between child views displayed inthe layout container may be shown in (4) in FIG. 17. Horizontal spacings between adjacent childviews are equal or substantially equal, and each are denoted as a spacing C. In addition, adistance between a left edge of the 1st child view and a left edge of the layout container is equalto a sum of a left inner margin of the layout container and the spacing C, and a distance betweena right edge of the last child view in the layout container and a right edge of the layout containeris equal to a sum of a right inner margin of the layout container and the spacing C.

[00322] For another example, the layout orientation of the layout container is a verticalorientation, and the second-type equalization capability of the layout container is enabled. Insome examples, when no inner margin is set for the layout container, an available height of thelayout container is a height of the layout container. A location relationship between child viewsdisplayed in the layout container may be shown in (3) in FIG. 18. A distance between an upperedge of the 1st child view and an upper edge of the layout container, a distance between a loweredge of the last child view in the layout container and a lower edge of the layout container, and aspacing between adjacent child views are equal or substantially equal. In some other examples,the layout container sets an inner margin in the layout orientation, for example, an upper innermargin and a lower inner margin. In this case, available height of the layout container = height ofthe layout container - upper inner margin - lower inner margin. Therefore, a locationrelationship between child views displayed in the layout container may be shown in (4) in FIG.18. Vertical spacings between adjacent child views are equal or substantially equal, and each aredenoted as a spacing D. In addition, a distance between an upper edge of the 1st child view andan upper edge of the layout container is equal to a sum of an upper inner margin of the layoutcontainer and the spacing D, and a distance between a lower edge of the last child view in thelayout container and a lower edge of the layout container is equal to a sum of a lower innermargin of the layout container and the spacing D.

[00323] In a specific implementation, an equalization capability may be set for a layoutcontainer including a plurality of same or similar child views. The child view is, for example, atext view, a button view, an image view, or an icon button view. When a width or a height of thelayout container changes, a spacing between child views may automatically and adaptivelychange based on the width or the height of the layout container, so as to meet displayrequirements of electronic devices having different screen dimensions. It can be learned that theequalization capability in this solution can enable electronic devices having different screenparameters to present different display effects based on a same layout setting, reducedevelopment and maintenance workload of developers, and meet display requirements of varioustypes of electronic devices.

[00324] In some other embodiments, the spacing threshold A or the spacing threshold B maybe further set for the layout container with the equalization capability enabled, so as to restrict arange of an adjusted spacing between child views. The adjusted spacing between child views isnot greater than the spacing threshold A. The adjusted spacing between child views is not lessthan the spacing threshold B.

[00325] For example, an example in which the layout orientation of the layout container is ahorizontal orientation and the first-type equalization capability is enabled is used for description.According to the foregoing method, the spacing between child views is determined as a spacingE based on the available space of the layout container and the dimension of each child view.Then, the spacing E is compared with the spacing threshold A. If the spacing E is greater than thespacing threshold A, the spacing between adjacent child views is determined as the spacingthreshold A, and the spacing between the left edge of the 1st child view and the left edge of thelayout container is adjusted and / or the spacing between the right edge of the last child view andthe right edge of the layout container is adjusted.

[00326] For example, as shown in (1) in FIG. 19, the layout container determines the spacingbetween child views as the spacing E based on the available space of the layout container and thedimension of the child view. In this case, the spacing E is greater than the spacing threshold A. Inan example, as shown in (2) in FIG. 19, it is determined that the spacing between child views isequal to the spacing threshold A, and all child views are centered (that is, horizontally centered)in the layout container as a whole. In this case, the spacing between the left edge of the 1st childview and the left edge of the layout container increases, and the spacing between the right edgeof the last child view and the right edge of the layout container increases. In another example, asshown in (3) in FIG. 19, it is determined that the spacing between child views is equal to thespacing threshold A, and all child views are left-aligned in the layout container as a whole. Inthis case, only the spacing between the right edge of the last child view and the right edge of thelayout container increases. In still another example, as shown in (4) in FIG. 19, it is determinedthat the spacing between child views is equal to the spacing threshold A, and all child views areright-aligned in the layout container as a whole. In this case, only the spacing between the leftedge of the 1st child view and the left edge of the layout container increases.

[00327] If the layout orientation of the layout container is a horizontal orientation and thesecond-type equalization capability is enabled, when it is determined that the spacing betweenadjacent child views is greater than the distance threshold A, adjustment may also be performedby using a method that is the same as a method for enabling the first-type equalization capability.

[00328] If the layout orientation of the layout container is a vertical orientation and theequalization capability (including the first-type equalization capability and the second-typeequalization capability) is enabled, when it is determined that the spacing between adjacent childviews is greater than the distance threshold A, the spacing between adjacent child views is stilldetermined as the spacing threshold A, and the spacing between the upper edge of the 1st childview and the upper edge of the layout container is adjusted and / or the spacing between the loweredge of the last child view and the lower edge of the layout container is adjusted. The childviews in the layout container may be centered (that is, vertically centered), top-aligned, orbottom-aligned. For details, refer to the descriptions provided when the layout orientation is ahorizontal orientation. Details are not described herein again.

[00329] For another example, an example in which the layout orientation of the layoutcontainer is a horizontal orientation and the first-type equalization capability is enabled is usedfor description. According to the foregoing method, the spacing between child views isdetermined as a spacing E based on the available space of the layout container and the dimensionof each child view. Then, the spacing E is compared with the spacing threshold B. If the spacingE is less than the spacing threshold B, the spacing between adjacent child views is determined asthe spacing threshold B. In this case, the 1st child view and / or the last child view display / displayspartial content. For example, if the child views are centered, a left part of the 1st child view and aright part of the last child view may be truncated and not displayed. If the child views areleft-aligned, a child view arranged to the right may be truncated and not displayed. If the childviews are right-aligned, a child view arranged to the left may be truncated and not displayed.

[00330] In some other embodiments, the layout container may further set a hiding capability.Therefore, after the spacing E is adjusted to the spacing threshold B, when the layout containerstill cannot display all child views, the hiding capability may be triggered. After the hidingcapability is triggered, a hidden child view may be determined based on hiding priorities of thechild views, that is, a quantity of child views displayed in the layout container is reduced. In thiscase, the spacing between adjacent child views is re-determined based on an adjusted quantity ofchild views and the available space of the layout container.

[00331] It should be noted that the spacing between child views is first divided based on theequalization capability. When a divided spacing between child views is less than the spacingthreshold B, the hiding capability is triggered, and then the spacing between displayed childviews is determined by using the equalization capability. In some other examples, a hidden childview may be first determined based on the hiding capability, and then the spacing betweendisplayed child views is determined based on the equalization capability. This is not specificallylimited in this embodiment of this application.

[00332] In some other embodiments, the layout container may further set a wrappingcapability. Therefore, after the spacing E is adjusted to the spacing threshold B, when the layoutcontainer still cannot display all child views, the wrapping capability may be triggered. After thewrapping capability is triggered, a quantity of rows or a quantity of columns in which the layoutcontainer displays these child views and a quantity of child views displayed in each row or eachcolumn may be first determined. In this case, the layout container may determine a spacingbetween child views in each row or each column based on the quantity of child views displayedin each row or each column and dimensions of the child views.

[00333] It should be noted that the spacing between child views is first divided based on theequalization capability. When a divided spacing between child views is less than the spacingthreshold B, the wrapping capability is triggered, and then the spacing between child viewsdisplayed in each row or each column is determined by using the equalization capability. In someother examples, a quantity of rows or a quantity of columns included in the layout container maybe first determined based on the wrapping capability, and then a spacing between child views ineach row is determined based on the equalization capability. This is not specifically limited inthis embodiment of this application.

[00334] An example in which the layout orientation of the layout container is a horizontalorientation and the first-type equalization capability is enabled is used above for description. Ifthe layout orientation of the layout container is a horizontal orientation and the second-typeequalization capability is enabled, or the layout orientation of the layout container is a verticalorientation and the equalization capability (including the first-type equalization capability andthe second-type equalization capability) is enabled, when it is determined that the spacingbetween adjacent child views is less than the distance threshold B, adjustment may also beperformed by using a similar method.

[00335] It should be noted that the foregoing embodiment is described by using an example inwhich dimensions of child views included in a layout container are the same. In this application,dimensions of child views in a layout container with an equalization capability enabled are notlimited, and the dimensions of the child views may be the same or may be different.

[00336] In addition, as mentioned above, after the equalization capability is enabled, spacingsbetween adjacent child views in the layout container may be equal or substantially equal, or maybe different. For example, allocation is performed by using another rule. The following providesseveral examples.

[00337] For example, as shown in (1) in FIG. 20, spacings between adjacent child views arein ascending order. Spacing 1 < spacing 2 < spacing 3. Alternatively, as shown in (2) in FIG. 20,spacings between adjacent child views are in descending order. Spacing 1 > spacing 2 > spacing3. Alternatively, as shown in (3) in FIG. 20, spacings between adjacent child views alternatelychange. Spacing 4 < spacing 5.

[00338] The following provides an example of one layout file (an XML file). A layoutcontainer with an equalization capability enabled is set in the layout file, and the layout containerincludes four child views: four image views.<hwLayoutxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto"android:layout_height="match_parent"android:layout_width="match_parent" / * omit other configurations * / android:orientation="horizontal" / / set a layout orientation of the layoutcontainerapp: equalization capability enablement="true" / / enable an equalizationcapabilityapp: equalization capability type="first type"> / / set the equalizationcapability as the first-type equalization capability<ImageView / / child view 1 in the layout container / * omit other configurations * / / ><ImageView / / child view 2 in the layout container / * omit other configurations * / / ><ImageView / / child view 3 in the layout container / * omit other configurations * / / ><ImageView / / child view 4 in the layout container / * omit other configurations * / / >< / hwLayout>

[00339] The foregoing embodiment is a solution in which the developer designs an adaptivedisplay interface layout by setting an attribute value related to an equalization capability of alayout container in a layout file (for example, an XML file). Alternatively, an attribute valuerelated to an equalization capability of a layout container may be set in a Java source code file byadding a call interface.

[00340] Table 6 shows an example of an interface corresponding to the attribute value relatedto the equalization capability of the layout container.Table 6

[00341] The meanings of the equalization capability are described in detail above. Adeveloper may configure a layout file based on a layout design of each display interface in anapplication with reference to an equalization capability, another adaptive layout capability, and abasic layout capability (for example, an Android native attribute), pack the layout file, othersource code and resources, and the like of the application into an installation package (forexample, an APK file), and release the installation package to an application market. Anelectronic device downloads the installation package from the application market, and installs theapplication. The following describes in detail a solution of implementing adaptive layout basedon the foregoing layout file when the electronic device runs the application.

[00342] Specifically, the mobile phone performs a measurement procedure shown in FIG. 21Afor each layout container in the layout file. The method specifically includes the following steps.

[00343] S2100: Obtain a layout parameter of the layout container.

[00344] The layout parameter of the layout container includes whether the layout containerenables an equalization capability, a child view included in the layout container, and a layoutparameter of the child view. If the equalization capability is enabled, the layout parameter of thelayout container further includes an equalization type, a spacing threshold A, a spacing thresholdB, and the like. After it is determined that the layout container enables the equalization capability,the following steps are performed.

[00345] S2101: Measure a dimension of each child view in the layout container in a layoutorientation.

[00346] For example, a dimension of the child view, including the dimension in the layoutorientation, is first obtained by using an Android native measurement method and the layoutparameter of the child view.

[00347] S2102: Determine whether the layout container has a plurality of rows / columns; andif yes, perform step S2104; or if not, perform step S2103.

[00348] In some examples, the layout container further enables a wrapping capability. In thiscase, a quantity of rows or a quantity of columns included in the layout container and a quantityof child views included in each row or each column need to be first determined based on anattribute related to the wrapping capability. For a value of a spacing between child views in eachrow or each column, if the layout container does not enable the wrapping capability, the layoutcontainer includes child views in one row or one column, and a spacing between the child viewsin one row or one column is calculated.

[00349] S2103: Determine a spacing E between child views in the layout container based onthe equalization type.

[00350] For example, the spacing E between child views is determined based on theequalization type, a dimension of the layout container, an inner margin, the layout orientation,and the dimension of the child view. Adjacent child views have an equal spacing E.

[00351] For first-type equalization, spacing E = [dimension space of the layout container inthe layout orientation - inner margin in the layout orientation - Σ(w1, w2, ..., wN)] / (N - 1). Forsecond-type equalization, spacing E = [dimension space of the layout container in the layoutorientation - inner margin in the layout orientation - Σ(w1, w2, ..., wN)] / (N + 1).

[00352] The layout container includes N child views, where Wi is a dimension of the ith childview in the layout orientation, i = 1, 2, ..., or N, and N is an integer greater than 1.

[00353] Then, step S2105 is performed.

[00354] S2104: Calculate a spacing E between child views in each row / column based on theequalization type.

[00355] The spacing E is calculated based on the quantity of child views in each row / columnand the dimension of the child view. For a specific calculation method, refer to the descriptionsin step S2103.

[00356] S2105: Determine whether the spacing E is greater than the spacing threshold A; andif yes, perform step S2106; otherwise, perform step S2107.

[00357] S2106: Determine that a spacing between adjacent child views is equal to the spacingthreshold A.

[00358] S2107: Determine whether the spacing E is less than the spacing threshold B; and ifyes, perform step S2108; otherwise, perform step S2109.

[00359] S2108: Determine that a spacing between adjacent child views is equal to the spacingthreshold B.

[00360] S2109: Determine a location of each child view in the layout container.

[00361] After the spacing between adjacent child views is determined, all child views arecentered, or left-aligned, or right-aligned, or top-aligned, or bottom-aligned in the layoutcontainer as a whole, to determine the location of each child view.

[00362] It should be noted that, if the spacing between adjacent child views is adjusted basedon the spacing threshold A or the spacing threshold B, when all the child views are centered, orleft-aligned, or right-aligned, or top-aligned, or bottom-aligned in the layout container as a whole,a distance between an outer edge of each of child views on both sides and the layout containermay further need to be adjusted. For a specific adjustment process, refer to related content in FIG.19. Details are not described herein again.

[00363] It should be noted that, if the first row has only one child view, the child view may becentered. If the first row has a plurality of child views, the plurality of child views are displayedbased on the equalization type.

[00364] If the first row has only one child view and the second row starts to have a pluralityof child views, display starts from the second row based on the equalization type. The third rowand subsequent rows may be displayed based on a calculated spacing in the second row. In thisway, starting from the second row, each child view may present a mesh effect. Alternatively, insome other examples, a spacing between adjacent child views may be independently calculatedbased on data of a child view included in each row and a width (or a height) of each child viewin the third row and subsequent rows, and display is performed based on the calculated spacing.

[00365] It can be understood that, when electronic devices (for example, a mobile phone and atablet computer) having different screen dimensions use a same layout file (including a layoutcontainer provided with an equalization capability), according to the measurement procedure inFIG. 21A, application interfaces finally drawn may present different layout effects.

[00366] For example, a screen width of the mobile phone is 720 pixels, and a screen width ofthe tablet computer is 1280 pixels. Both the mobile phone and the tablet computer use a sameinstallation package to install a gallery application. A layout file corresponding to a page of thegallery application includes a layout container configured to display navigation, and the layoutcontainer enables a second-type equalization capability. The layout container includes fourhorizontally arranged child views (which are respectively "Photos", "Albums", "Moments", and"Discover"). Widths of the four child views are equal and each are 80 pixels. An inner margin ofthe layout container is set to 0 pixels.

[00367] Therefore, when the mobile phone draws the page of the gallery application andperforms the measurement procedure in FIG. 21A for the layout container, the mobile phonecalculates a spacing between child views: spacing between child views = [dimension space of thelayout container in a layout orientation - inner margin in the orientation direction - Σ(w1, w2, ...,wN)] / (N + 1) = (720 - 0 - 80 * 4) / 5 = 80 pixels. The mobile phone displays an interface 211shown in FIG. 21B(1), where a spacing between child views in a layout container 212 is 80pixels.

[00368] When the tablet computer draws the page of the gallery application and performs themeasurement procedure in FIG. 21A for the layout container, the tablet computer calculates aspacing between child views: spacing between child views = [dimension space of the layoutcontainer in a layout orientation - inner margin in the orientation direction - Σ(w1, w2, ...,wN)] / (N + 1) = (1280 - 0 - 80 * 4) / 5 = 192 pixels. The tablet computer displays an interface 213shown in FIG. 21B(2), where a spacing between child views in a layout container 214 is 192pixels.

[00369] FIG. 22 is another schematic diagram of an adaptive application interface layoutmethod according to an embodiment of this application. In an application development phase, adeveloper may set an attribute related to an equalization capability in a layout file such as anXML file. For example, the developer enables the equalization capability, sets an equalizationtype, and sets a spacing threshold A and a spacing threshold B. Subsequently, the developerpacks the layout file, other application code and resources, and the like into an installationpackage, and releases the installation package to an application market. Then, a user maydownload the installation package from the application market by using an electronic device, andinstall the application. When the electronic device runs the application, a layout module in theelectronic device parses the attribute related to the equalization capability from the layout file, toobtain an attribute value related to the equalization capability, and sends the attribute value to anequalization module in the electronic device. Then, the layout module performs measurement,and starts an equalization capability process. In other words, the equalization module calculates aparameter of a related view such as a dimension of the view based on the attribute value relatedto the equalization capability. The layout module performs layout based on an updated parameterof the view, to obtain a location of the view on a specific display interface of the application.Finally, the electronic device may draw and display the specific display interface. In a specificexample, the equalization module may perform related steps in FIG. 21A. The layout modulemay be a measurement module and a layout module in a native view system of an Androidsystem. The equalization module is a newly added function module in the measurement modulein the native view system of the Android system in this application.

[00370] (4) Hiding capability

[00371] When developing an application, after adding dependency of an adaptive layoutattribute package, a developer may set a layout container (that is, a ViewGroup) having a hidingcapability on a display interface. Specifically, when editing a layout file of the display interface,the developer may set an attribute value related to the hiding capability of the ViewGroup in thelayout file (for example, an XML file), or may set an attribute value related to the hidingcapability of the ViewGroup in a Java source code file by adding a call interface.

[00372] Table 7 shows an example of an attribute related to the hiding capability.Table 7

[00373] It should be noted that, when setting an attribute of a layout container, the developermay enable a horizontal hiding capability / vertical hiding capability of the layout containerthrough horizontal hiding capability enablement / vertical hiding capability enablement. Inaddition, a hiding priority may be further set for a child view (a View or a ViewGroup in thelayout container). Subsequently, when running the application and drawing a child view in thelayout container, if the electronic device determines, based on a dimension of the layoutcontainer, that not all child views can be displayed in a horizontal direction / vertical direction, theelectronic device may determine a hidden child view or a displayed child view based on a hidingpriority of each child view. Then, the electronic device draws each child view in the layoutcontainer, so as to implement an adaptive layout on the electronic device.

[00374] It should be further noted that each attribute in Table 7 is merely an example. In someother embodiments, hiding capability enablement and a hiding priority may also be set. In thisway, after the hiding capability of the layout container is enabled, a hidden child view may bedetermined by default in a layout direction of the layout container based on a hiding priority ofthe child view. Optionally, an orientation of the hiding capability may be further set. After theuser sets the orientation of the hiding capability, a hidden child view is determined in a specifiedorientation based on a hiding priority of the child view. This is not limited in this embodiment ofthis application.

[00375] The meaning of each attribute related to the hiding capability and an effect ofdisplaying the layout container and the child view are described in detail below with reference tothe accompanying drawings by using Table 7 as an example.

[00376] In some embodiments, a horizontal hiding capability of the layout container may beenabled, and a horizontal hiding priority or a horizontal display priority is set for each child viewin the layout container. Herein, the horizontal hiding priority is used as an example fordescription. Therefore, after a width of the layout container is determined, whether the layoutcontainer can display all child views is determined based on widths of child views horizontallyarranged in the layout container. If yes, all the child views are displayed. If not, a hidden childview, that is, a child view not displayed in the layout container, is further determined based onthe horizontal hiding priority of each child view. In some examples, when running theapplication, the electronic device does not draw a child view that is determined to be hidden inthe layout container, or draws only a child view that is determined to be displayed in the layoutcontainer. It should be further noted that, in this application, displaying a child view meanscompletely displaying content of the child view, that is, displaying all content of the child view.

[00377] For example, it is set that a layout container includes six horizontally arranged childviews: a child view A to a child view F. In addition, horizontal hiding priorities of the six childviews are arranged in ascending order: (child view A, child view B, and child view D) < (childview E and child view F) < child view C. The horizontal hiding priorities of the child view A, thechild view B, and the child view D are the same, and the horizontal hiding priorities of the childview E and the child view F are the same.

[00378] (1) in FIG. 23 is an effect diagram of a layout container displayed by an electronicdevice 1. In this case, available width of the layout container displayed by the electronic device 1≥ sum of widths of all child views in the layout container. Herein, available width of the layoutcontainer = total width of the layout container - left and right inner margins. In (1) in FIG. 23, anexample in which the left and right inner margins are 0 is used for description. Therefore, thelayout container on the electronic device 1 may horizontally display all the child views (the childview A to the child view F).

[00379] It should be noted that, if a spacing between adjacent child views is further set, thesum of the widths of all the child views in the layout container includes the width of each childview and the spacing between adjacent child views. Similarly, in the following, when it isdetermined whether a plurality of child views can be placed, a sum of widths of the plurality ofchild views includes a spacing between adjacent child views in the plurality of child views. Thisis not specially described below. Adjacent child views may have a same spacing, or may havedifferent spacings. In some examples, the spacing between adjacent child views may be a fixedvalue that is set in the layout file. In some other examples, an initial value of the spacing betweenadjacent child views may alternatively be set in the layout container. After a hidden child view ora displayed child view in the layout container is determined based on the initial value of thespacing between adjacent child views and the width of each child view, the spacing betweenadjacent child views is adjusted based on the width of the layout container and a width of thedisplayed child view. This is not limited in this embodiment of this application.

[00380] When available width of the layout container < sum of the widths of all the childviews in the layout container, it is determined that the layout container cannot display all thechild views. In this case, the hidden child view or the displayed child view is determined basedon an available space of the layout container, the width of each child view, and the horizontalhiding priority of each child view.

[00381] In a technical solution, when the layout container cannot display all child views, achild view of a high horizontal hiding priority in the layout container is preferentially hidden in asequence of horizontal hiding priorities of the child views.

[00382] For example, (2) in FIG. 23 is an effect diagram of a layout container displayed by anelectronic device 2. Because available width of the layout container displayed by the electronicdevice 2 < sum of widths of child views in the layout container, a child view of a highesthorizontal hiding priority (for example, the child view C) in the layout container is preferentiallyhidden. After the child view C is hidden, the layout container on the electronic device 2 candisplay the other five child views, that is, the child view A, the child view B, and the child viewD to the child view F.

[00383] For another example, (3) in FIG. 23 is an effect diagram of a layout containerdisplayed by an electronic device 3. Because available width of the layout container displayed bythe electronic device 3 < sum of widths of child views in the layout container, a child view of ahighest horizontal hiding priority (for example, the child view C) in the layout container ispreferentially hidden. Then, it is determined, based on widths of the other child views (forexample, the child view A, the child view B, and the child view D to the child view F), that thelayout container still cannot display all the five child views. Further, a child view whosehorizontal hiding priority is only second to that of the child view C (for example, the child viewE and the child view F) in the layout container is further determined to be hidden. Then, it isdetermined, based on widths of the other child views (the child view A, the child view B, and thechild view D), that the layout container can display all the three child views. In this case, theelectronic device 3 displays the three child views.

[00384] It should be noted that, in some examples, a plurality of child views of a samehorizontal hiding priority are simultaneously hidden or simultaneously displayed. For example,the child view E and the child view F are child views of a same horizontal hiding priority. In thiscase, the child view E and the child view F are simultaneously displayed in the layout container,or are not simultaneously displayed in the layout container. In some other examples, it mayalternatively be determined, in a plurality of child views of a same horizontal hiding priority, thata child view arranged after a current child view is preferentially hidden. For example, the childview E and the child view F are child views of a same horizontal hiding priority. When it isdetermined to hide a child view, the child view F is hidden prior to the child view E. In otherwords, when it is determined that the electronic device 3 cannot display all the five child views(the child view A, the child view B, and the child view D to the child view F), it is furtherdetermined to hide the child view F. In this case, it is determined whether the layout containercan display all other child views (the child view A, the child view B, the child view D, and thechild view E). If it is determined that the four child views can be displayed, as shown in (4) inFIG. 23, the layout container displays the four child views. Certainly, for child views of a samehorizontal hiding priority, a child view that is preferentially hidden may be determined by usinganother method or may be determined randomly. This is not limited in this embodiment of thisapplication.

[00385] It should be noted that a sequence of arranging child views herein may be determinedbased on a user's reading habit of text. For example, the user's reading habit may be specificallydetermined based on a language of the text displayed on the child views. Generally, forlanguages such as Chinese and English, the user is accustomed to reading from left to right andfrom top to bottom. Therefore, for a plurality of horizontally arranged child views, it may beconsidered that a left child view is arranged before a right child view; and for a plurality ofvertically arranged child views, it may be considered that an upper child view is arranged beforea lower child view. For some other languages, for a plurality of horizontally arranged child views,it may be considered that a rear child view is arranged before a left child view; and for a pluralityof vertically arranged child views, it may be considered that a lower child view is arrangedbefore an upper child view. In addition, the user may alternatively set whether a plurality ofhorizontally arranged child views are arranged first on the left side or the right side and / or setwhether a plurality of vertically arranged child views are arranged first on the upper side or thelower side. The foregoing sequence of arranging child views is merely an example, and is notlimited in this application.

[00386] In another technical solution, when the layout container cannot display all child views,child views that can be displayed in the layout container are sequentially calculated in a sequenceof horizontal hiding priorities of the child views.

[00387] Specifically, child views that are to be determined whether to be displayed througheach calculation are determined in ascending order of the horizontal hiding priorities of the childviews, where the child views are referred to as to-be-determined child views for short.Horizontal hiding priorities of the to-be-determined child views in each calculation are the same.In each calculation process, if available width of the layout container - sum of widths of childviews determined to be displayed ≥ sum of widths of to-be-determined child views in currentcalculation, it is determined that the layout container can display the to-be-determined childviews in current calculation. If it is determined that available width of the layout container < sumof the widths of the to-be-determined child views in current calculation, it is determined that thelayout container cannot display the to-be-determined child views in current calculation.

[00388] In addition, if available width of the layout container - sum of widths of child viewsdetermined to be displayed > sum of widths of to-be-determined child views in currentcalculation, it needs to be further determined whether another child view can be placed in thelayout container. Another child view whose horizontal hiding priority is higher than that of thecurrent to-be-determined child view is determined as a to-be-determined child view in nextcalculation.

[00389] If available width of the layout container - sum of widths of child views determinedto be displayed = sum of widths of to-be-determined child views in current calculation, itindicates that the layout container cannot display more child views other than theto-be-determined child views in current calculation.

[00390] The following provides specific description with reference to an instance. To simplifydescription, w(M) is used to identify a width of a child view M, where M is a variable. Forexample, w(A) indicates a width of a child view A.

[00391] For example, as shown in (2) in FIG. 23, available width of the layout containerdisplayed by the electronic device 2 < sum of the widths of the child views in the layoutcontainer.

[00392] First, it is determined that a child view of a lowest horizontal hiding priority (or ahighest horizontal display priority) (for example, the child view A, the child view B, and thechild view D) in the layout container is a child view that is first displayed, and is ato-be-determined child view in current calculation. Because available space of the layoutcontainer of the electronic device 2 > Σ[w(A), w(B), w(D)], it is determined that the child viewA, the child view B, and the child view D can be displayed in the layout container. In addition, itneeds to be further determined whether another child view can be displayed.

[00393] It should be noted that, if it is determined that available width of the layout container= Σ[w(A), w(B), w(D)], only the child view A, the child view B, and the child view D can bedisplayed in the layout container.

[00394] Further, it is determined that another child view of a slightly higher horizontal hidingpriority (for example, the child view E and the child view F) is a to-be-determined child view incurrent calculation. When it is determined that available width of the layout container - Σ[w(A),w(B), w(D)] ≥ Σ[w(E), w(F)], it is determined that the child view E and the child view F can befurther displayed in the layout container. In this case, if available width of the layout container -Σ[w(A), w(B), w(D)] > Σ[w(E), w(F)], it further needs to be determined whether another childview can be displayed.

[00395] It should be noted that, if it is determined that available width of the layout container- Σ[w(A), w(B), w(D)] = Σ[w(E), w(F)], only the child view A, the child view B, the child viewD, the child view E, and the child view F can be displayed in the layout container.

[00396] Further, it is determined whether another child view of a higher horizontal hidingpriority (for example, the child view C) can be displayed in the layout container. In this case,available width of the layout container - Σ[w(A), w(B), w(D), w(E), w(F)] < w(C), the childview C cannot be displayed in the layout container.

[00397] In conclusion, the layout container of the electronic device 2 displays a total of fivechild views: the child view A, the child view B, and the child view D to the child view F.

[00398] For another example, as shown in (2) in FIG. 23, available width of the layoutcontainer displayed by the electronic device 2 < sum of the widths of the child views in thelayout container.

[00399] First, it is determined that a child view of a lowest horizontal hiding priority (forexample, the child view A, the child view B, and the child view D) in the layout container is achild view that is first displayed, and is a to-be-determined child view in current calculation.Because available space of the layout container of the electronic device 2 > Σ[w(A), w(B),w(D)], it is determined that the child view A, the child view B, and the child view D can bedisplayed in the layout container. In addition, it needs to be further determined whether anotherchild view can be displayed.

[00400] Further, it is determined that another child view of a slightly higher horizontal hidingpriority (for example, the child view E and the child view F) is a to-be-determined child view incurrent calculation. When it is determined that available width of the layout container - Σ[w(A),w(B), w(D)] < Σ[w(E), w(F)], it is determined that the child view E and the child view F cannotbe displayed in the layout container. In this case, only the child view A, the child view B, and thechild view D are displayed in the layout container.

[00401] In some other embodiments, a vertical hiding capability of the layout container maybe enabled, and a vertical hiding priority or a vertical display priority is set for each child view inthe layout container. Therefore, after a height of the layout container is determined, whether thelayout container can display all child views is determined based on heights of child viewsvertically arranged in the layout container. If yes, all the child views are displayed. If not, ahidden child view, that is, a child view not displayed in the layout container, is furtherdetermined based on the vertical hiding priority of each child view. For a specificimplementation of the vertical hiding capability, refer to related content in the horizontal hidingcapability. Details are not described herein again.

[00402] In a specific implementation, a hiding capability may be set for a layout containerincluding a plurality of child views. The child view is, for example, a text view, a button view, animage view, or an icon button view (ImageButton View). When a width or a height of a layoutcontainer changes, some child views in the layout container may be automatically determined tobe hidden, so as to meet display requirements of electronic devices having different screendimensions. It can be learned that the hiding capability in this solution can enable electronicdevices having different screen parameters to present different display effects based on a samelayout setting, reduce development and maintenance workload of developers, and meet displayrequirements of various types of electronic devices.

[00403] The following provides an example of one layout file (an XML file). A layoutcontainer with a hiding capability enabled is set in the layout file, and the layout containerincludes four child views: four image views.<hwLayoutxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto" / * omit other configurations * / android:orientation="horizontal"app: vertical hiding capability enablement="true" / / enable a vertical hidingcapabilityapp: wrapping capability enablement="true" / / enable a wrappingcapabilityapp: wrapping alignment mode="end"> / / set the wrapping alignment mode. ForChinese and English, "end" corresponds to right alignment<ImageView / / set a child view 1 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="5" / / set a vertical hiding priority of thechild view 1app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 1<ImageView / / set a child view 2 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="3" / / set a vertical hiding priority of thechild view 2app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 2<ImageView / / set a child view 3 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="2" / / set a vertical hiding priority of thechild view 3app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 3<ImageView / / set a child view 4 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="4" / / set a vertical hiding priority of thechild view 4app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 4<ImageView / / set a child view 5 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="1" / / set a vertical hiding priority of thechild view 5app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 5< / hwLayout>

[00404] The foregoing embodiment is a solution in which the developer designs an adaptivedisplay interface layout by setting an attribute value related to a hiding capability of a layoutcontainer in a layout file (for example, an XML file). Alternatively, an attribute value related to ahiding capability of a layout container may be set in a Java source code file by adding a callinterface.

[00405] Table 8 shows an example of an interface corresponding to the attribute value relatedto the hiding capability of the layout container.Table 8

[00406] The meanings of the hiding capability are described in detail above. A developer mayconfigure a layout file based on a layout design of each display interface in an application withreference to a hiding capability, another adaptive layout capability, and a basic layout capability(for example, an Android native attribute), pack the layout file, other source code and resources,and the like of the application into an installation package (for example, an APK file), andrelease the installation package to an application market. An electronic device downloads theinstallation package from the application market, and installs the application. The followingdescribes in detail a solution of implementing adaptive layout based on the foregoing layout filewhen the electronic device runs the application.

[00407] Specifically, the mobile phone performs a measurement procedure shown in FIG. 24Afor each layout container in the layout file. The method specifically includes the following steps.

[00408] S2400: Obtain a layout parameter of the layout container.

[00409] The layout parameter of the layout container includes whether to enable a horizontalhiding capability and a vertical hiding capability, a dimension of the layout container, an innermargin, and the like.

[00410] S2401: Determine that the layout container enables the horizontal hiding capability,and obtain all child views included in the layout container.

[00411] Herein, an example in which the layout container enables the horizontal hidingcapability is used for description. Each child view included in the layout container and a layoutparameter corresponding to each child view are obtained. The layout parameter corresponding toeach child view includes an attribute value of a dimension of each child view, and a horizontalhiding priority or a horizontal display priority corresponding to each child view. In someexamples, if no hiding priority is set for a child view, it may be considered that the child view isa child view of a lowest hiding priority, or a child view that needs to be displayed.

[00412] S2402: Measure each child view in the layout container, and store a width of eachchild view.

[00413] Based on the layout parameter of each child view (other than the horizontal hidingpriority), a parameter transferred from the layout container, and the like, initial measurement isperformed on each child view in the layout container (for example, measurement is performedbased on an Android original measurement procedure), to obtain and store the width of eachchild view.

[00414] S2403: Determine a plurality of batches of child views based on the horizontal hidingpriorities of the child views, and start to calculate a sum of widths of a batch of child views of alowest horizontal hiding priority.

[00415] In other words, one or more child views of a same horizontal hiding priority aredetermined as a batch of child views. Child views displayed in the layout container aredetermined in batches in ascending order of horizontal hiding priorities. The first batch of childviews is a batch of child views of a lowest horizontal hiding priority. A sum of widths of thebatch of child views is calculated.

[00416] S2404: Determine whether available space of the layout container < sum of widths ofchild views that have been determined to be displayed and a current batch of child views; and ifyes, perform step S2405; or if not, perform step S2406.

[00417] Herein, available space of the layout container = width of the layout container - leftand right inner margins. When the first batch of child views are calculated, there are no childviews that have been determined to be displayed.

[00418] If available space of the layout container < sum of the widths of the child views thathave been determined to be displayed and the current batch of child views, it indicates that theavailable space of the layout container cannot be used to place the current batch of child views,that is, step S2405 is performed. If available space of the layout container ≥ sum of the widths ofthe child views that have been determined to be displayed and the current batch of child views, itindicates that the available space of the layout container can be used to place the current batch ofchild views.

[00419] It should be noted that, if a spacing between child views is further set, a spacingbetween the child views that have been determined to be displayed and a spacing between thecurrent batch of child views need to be further added during determining.

[00420] S2405: Determine that the layout container neither displays the current batch of childviews nor displays other child views whose hiding priority is higher than that of the current batchof child views.

[00421] The measurement procedure ends.

[00422] S2406: Determine that the layout container displays the current batch of child views.

[00423] S2407: Determine whether all batches of child views are traversed; and if yes, end themeasurement procedure; or if not, perform step S2408.

[00424] S2408: Calculate a sum of widths of a next batch of child views whose hiding priorityis higher than that of the current batch of child views, and then perform step S2404.

[00425] The foregoing is described by using an example in which the horizontal hidingcapability is enabled. If the vertical hiding capability is enabled, calculation and determiningneed to be performed based on a height of the layout container and a height of each child view.For other content, refer to the related descriptions in FIG. 24A.

[00426] FIG. 24B is a schematic flowchart of another measurement method of a layoutcontainer according to an embodiment of this application. In other words, step S2403 to stepS2408 are replaced with step S2409 to step S2415. Details are as follows:

[00427] S2400: Obtain a layout parameter of the layout container.

[00428] The layout parameter of the layout container includes whether to enable a horizontalhiding capability and a vertical hiding capability, a dimension of the layout container, an innermargin, and the like.

[00429] S2401: Determine that the layout container enables the horizontal hiding capability,and obtain all child views included in the layout container.

[00430] Herein, an example in which the layout container enables the horizontal hidingcapability is used for description. Each child view included in the layout container and a layoutparameter corresponding to each child view are obtained. The layout parameter corresponding toeach child view includes an attribute value of a dimension of each child view, and a horizontalhiding priority or a horizontal display priority corresponding to each child view. In someexamples, if no hiding priority is set for a child view, it may be considered that the child view isa child view of a lowest hiding priority, or a child view that needs to be displayed.

[00431] S2402: Measure each child view in the layout container, and store a width of eachchild view.

[00432] Based on the layout parameter of each child view (other than the horizontal hidingpriority), a parameter transferred from the layout container, and the like, initial measurement isperformed on each child view in the layout container (for example, measurement is performedbased on an Android original measurement procedure), to obtain and store the width of eachchild view.

[00433] S2409: Determine whether available space of the layout container ≥ sum of thewidths of all the child views; and if yes, perform step S2410; otherwise, perform step S2411.

[00434] If a spacing between child views is further set, a child view spacing sum further needsto be added to the right of the inequality during determining.

[00435] S2410: Display all the child views in the layout container.

[00436] The measurement procedure ends.

[00437] S2411: Determine a plurality of batches of child views based on the horizontal hidingpriorities of the child views, and first hide a batch of child views of a highest horizontal hidingpriority.

[00438] S2412: Determine whether available space of the layout container ≥ sum of thewidths of all the child views - sum of widths of the child views determined to be hidden; and ifyes, perform step S2413; otherwise, perform step 814.

[00439] If a spacing between child views is further set, a spacing between child views otherthan the child views determined to be hidden further needs to be added to the right of theinequality during determining.

[00440] S2413: Display, in the layout container, child views other than the child viewsdetermined to be hidden.

[00441] The measurement ends.

[00442] S2414: Determine whether all batches of child views are traversed; and if yes, end themeasurement procedure; or if not, perform step S2415.

[00443] S2415: Determine a next batch of child views whose horizontal hiding priority islower than that of a current batch of child views, and then perform step S2412.

[00444] It can be understood that, when electronic devices (for example, a mobile phone and atablet computer) having different screen dimensions use a same layout file (including a layoutcontainer provided with a hiding capability), according to the measurement procedure in FIG.24A or FIG. 24B, application interfaces finally drawn may present different layout effects.

[00445] For example, a screen width of the mobile phone is 720 pixels, and a screen width ofthe tablet computer is 1280 pixels. Both the mobile phone and the tablet computer use a sameinstallation package to install a music application. A layout file corresponding to a play page ofthe music application includes a layout container configured to control play, and the layoutcontainer enables a hiding capability. The layout container includes five horizontally arrangedchild views (which are respectively "Previous", "Play / Pause", "Next", "More", and "Favorites").In addition, hiding priorities are set to be arranged in ascending order: ("Previous", "Play / Pause",and "Next") < "More" < "Favorites". In addition, widths of the five child views are equal to 100pixels, and a spacing between the child views is 180 pixels. An inner margin of the layoutcontainer is set to 0 pixels.

[00446] In this case, when the mobile phone draws the play page of the music application, andperforms the measurement procedure in FIG. 24A (FIG. 24A is used as an example) on thelayout container, the mobile phone determines that the first batch of displayed child views are"Previous", "Play / Pause", and "Next", and performs the following calculation: sum of widths ofthe three child views + sum of spacings between the three child views = 100 * 3 + 180 * 2 = 660pixels < screen width of the mobile phone 720 pixels. Therefore, the mobile phone determines todisplay the three child views. In this case, after the three child views are displayed, remainingscreen width of the mobile phone = 720 - 660 = 60 pixels. A next batch of child views aredetermined based on the hiding priority, namely, "More". If "More" needs to be displayed again,width that needs to be further occupied = 100 + 180 = 280 pixels > remaining screen width of themobile phone 60 pixels. In this case, the mobile phone determines not to display the currentbatch of child views and other child views. The mobile phone displays an interface 251 shown in(1) in FIG. 25. A layout container 252 displays three child views: "Previous", "Play / Pause", and"Next".

[00447] When the tablet computer draws the play page of the music application, and performsthe measurement procedure in FIG. 24A (FIG. 24A is used as an example) on the layoutcontainer, the tablet computer determines, through calculation, that the first batch of displayedchild views are "Previous", "Play / Pause", and "Next", and performs the following calculation:sum of widths of the three child views + sum of spacings between the three child views = 100 *3 + 180 * 2 = 660 pixels < screen width of the tablet computer 1280 pixels. Therefore, the tabletcomputer determines to display the three child views. In this case, after the three child views aredisplayed, remaining screen width of the tablet computer = 1280 - 660 = 620 pixels. A nextbatch of child views are determined based on the hiding priority, namely, "More". If "More"needs to be displayed again, width that needs to be further occupied = 100 + 180 = 280 pixels <remaining screen width of the tablet computer 620 pixels obtained after the three child views aredisplayed. Therefore, the tablet computer determines to further display "More". In this case,remaining screen width of the tablet computer = 620 - 280 = 340 pixels. Then, a next batch ofchild views are determined based on the hiding priority, namely, "Favorites". If "Favorites" needsto be displayed again, width that needs to be further occupied = 100 + 180 = 280 pixels <remaining screen width of the tablet computer 340 pixels. Therefore, the tablet computerdetermines to further display "More". The tablet computer displays an interface 253 shown in (2)in FIG. 25. A layout container 254 displays five child views: "Previous", "Play / Pause", "Next","More", and "Favorites".

[00448] FIG. 26 is another schematic diagram of an adaptive application interface layoutmethod according to an embodiment of this application. In an application development phase, adeveloper may set an attribute related to a hiding capability in a layout file such as an XML file.For example, a horizontal hiding capability or a vertical hiding capability is enabled, and ahorizontal hiding priority or a vertical hiding priority of each child view is set. Subsequently, thedeveloper packs the layout file, other application code and resources, and the like into aninstallation package, and releases the installation package to an application market. Then, a usermay download the installation package from the application market by using an electronic device,and install the application. When the electronic device runs the application, a layout module inthe electronic device parses the attribute related to the hiding capability from the layout file, toobtain an attribute value related to the hiding capability, and sends the attribute value to a hidingmodule in the electronic device. Then, the layout module performs measurement, and starts ahiding capability process. In other words, the hiding module calculates a parameter of a relatedview such as a dimension of the view based on the attribute value related to the hiding capability.The layout module performs layout based on an updated parameter of the view, to obtain alocation of the view on a specific display interface of the application. Finally, the electronicdevice may draw and display the specific display interface. In a specific example, the hidingmodule may perform related steps in FIG. 24A. The layout module may be a measurementmodule and a layout module in a native view system of an Android system. The hiding module isa newly added function module in the measurement module in the native view system of theAndroid system in this application.

[00449] (5) Stretching capability

[00450] When developing an application, after adding dependency of an adaptive layoutattribute package, a developer may set a ViewGroup having a stretching capability on a displayinterface. Specifically, when editing a layout file of the display interface, the developer may setan attribute value related to the stretching capability of the ViewGroup in the layout file (forexample, an XML file), or may set an attribute value related to the stretching capability of theViewGroup in a Java source code file by adding a call interface.

[00451] Table 9 shows an example of an attribute related to the stretching capability.Table 9

[00452] It should be noted that, when setting an attribute of a layout container, the developermay enable the stretching capability of the layout container through stretching capabilityenablement. Then, for a child view (that is, a View or a ViewGroup stored in the layout container)included in the layout container, a width of the child view is set to "match_parent", and / or aheight of the child view is set to "match_parent". Subsequently, when running the applicationand drawing the child view, the electronic device stretches the child view based on a dimensionof the layout container.

[00453] For example, when the layout container is set to have a horizontal stretchingcapability, and when the dimension of the layout container on the electronic device is 720*1080pixels, a dimension of the child view may be 720*600 pixels. When the dimension of the layoutcontainer on the electronic device is 1280*800 pixels, the dimension of the child view may be1280*600 pixels. For another example, the layout container is set to have a horizontal stretchingcapability, and both a left inner margin and a right inner margin are set to 10 pixels. When thedimension of the layout container on the electronic device is 720*1080 pixels, the dimension ofthe child view may be 700*600 pixels. When the dimension of the layout container on theelectronic device is 1280*800 pixels, the dimension of the child view may be 1260*600 pixels.

[00454] The meaning of each attribute related to the stretching capability and an effect ofdisplaying the layout container and the child view are described in detail below with reference tothe accompanying drawings.

[00455] In some embodiments, the developer may set horizontal stretching enablement of thelayout container to be enabled, or set vertical stretching enablement of the layout container to beenabled, or set horizontal stretching enablement and vertical stretching enablement of the layoutcontainer to be enabled.

[00456] For example, on an interface shown in (1) in FIG. 27, the child view completelyoccupies the layout container. After the stretching capability of the layout container is enabled,when the dimension of the layout container changes, the child view in the layout container isstretched in a specified direction.

[00457] In some examples, an attribute value of horizontal stretching capability enablement ofthe layout container is set to true, and the width of the child view is set to "match_parent". In thiscase, when the dimension of the layout container changes, the child view is horizontallystretched. In other words, as shown in (2) in FIG. 27, (3) in FIG. 27, and (4) in FIG. 27, thewidth of the child view adaptively changes with the width of the layout container.

[00458] It should be noted that, if the height of the layout container also changes, the childview performs adjustment based on a layout parameter that is set by the child view. For example,if the height of the child view is a fixed value, the height of the child view remains a fixed value.As the height of the layout container changes, if the child view does not completely occupy aspace of the layout container in a vertical direction, a vertical alignment manner of the child viewmay be further set. The vertical alignment manner includes vertical centering (as shown in (2) inFIG. 27), top alignment (as shown in (3) in FIG. 27), and bottom alignment. The top alignmentmeans that an upper border of the child view is aligned with an upper border of the layoutcontainer. The vertical centering means that a distance between the upper border of the childview and the upper border of the layout container is equal to a distance between a lower borderof the child view and a lower border of the layout container. The bottom alignment means thatthe lower border of the child view is aligned with the lower border of the layout container.Certainly, the distance between the upper border of the child view and the upper border of thelayout container (that is, an upper inner margin) may also be set. In this case, as shown in (4) inFIG. 27, when the height of the container dimension changes, the distance between the upperborder of the child view and the upper border of the layout container is kept as a specified value,and the distance between the lower border of the child view and the lower border of the layoutcontainer varies with the layout container. Alternatively, the distance between the lower border ofthe child view and the lower border of the layout container (that is, a lower inner margin) may beset. In this case, when the height of the container dimension changes, the distance between thelower border of the child view and the lower border of the layout container is kept as a specifiedvalue, and the distance between the upper border of the child view and the upper border of thelayout container varies with the layout container.

[00459] If the height of the child view is match_parent, the height of the child view varieswith the layout container.

[00460] In some other examples, an attribute value of vertical stretching capabilityenablement of the layout container is set to true, and the height of the child view is set to"match_parent". In this case, when the dimension of the layout container changes, the child viewis vertically stretched. In other words, as shown in (5) in FIG. 27, (6) in FIG. 27, and (7) in FIG.27, the height of the child view adaptively changes with the height of the layout container.

[00461] It should be noted that, if the width of the layout container also changes, the childview performs adjustment based on a layout parameter that is set by the child view. For example,if the width of the child view is a fixed value, the width of the child view remains a fixed value.As the width of the layout container changes, if the child view does not completely occupy aspace of the layout container in a horizontal direction, a horizontal alignment manner of the childview may be further set. The horizontal alignment manner includes horizontal centering (asshown in (5) in FIG. 27), left alignment (as shown in (6) in FIG. 27), and right alignment. Theleft alignment means that a left border of the child view is aligned with a left border of the layoutcontainer. The horizontal centering means that a distance between the left border of the childview and the left border of the layout container is equal to a distance between a right border ofthe child view and a right border of the layout container. The right alignment means that the rightborder of the child view is aligned with the right border of the layout container. Certainly, thedistance between the left border of the child view and the left border of the layout container (thatis, a left inner margin) may also be set. In this case, as shown in (7) in FIG. 27, when the widthof the container dimension changes, the distance between the left border of the child view andthe left border of the layout container is kept as a specified value, and the distance between theright border of the child view and the right border of the layout container varies with the layoutcontainer. Alternatively, the distance between the right border of the child view and the rightborder of the layout container (that is, a right inner margin) may be set. In this case, when thewidth of the container dimension changes, the distance between the right border of the childview and the right border of the layout container is kept as a specified value, and the distancebetween the left border of the child view and the left border of the layout container varies withthe layout container. For another example, if the height of the child view is match_parent, theheight of the child view varies with the layout container.

[00462] In some other examples, an attribute value of horizontal stretching capabilityenablement of the layout container is set to true, and the width of the child view is set to"match_parent"; and each attribute value of vertical stretching capability enablement of thelayout container is set to true, and the height of the child view is set to "match_parent". In thiscase, when the dimension of the layout container changes, the child view is horizontally andvertically stretched. In other words, as shown in (8) in FIG. 27, the height of the child viewadaptively changes with the height of the layout container, and the width of the child viewadaptively changes with the width of the layout container.

[00463] It can be learned that, based on the stretching capability provided in this embodimentof this application, the child view in the layout container having the stretching capability may beadaptively stretched based on the change of the layout container. Therefore, electronic deviceshaving different screen parameters can present different display effects based on a same layoutsetting, development and maintenance workload of developers is reduced, and displayrequirements of various types of electronic devices are met. For example, a stretching capabilitymay be set for a layout container in which a text view (for example, a TextView view or anEditText view) and a button view (for example, a Button view or an ImageButton view) arelocated. When the width and / or the height of the layout container change / changes, stretchingmay be adaptively performed in a specified direction, so as to meet a display requirement.

[00464] In some other embodiments, after setting the stretching capability of the layoutcontainer to be enabled, the developer may further set an inner margin of the layout container ina stretching direction. Therefore, when maintaining the inner margin from the layout container,the child view in the layout container may stretch in a specified direction as the dimension of thelayout container changes.

[00465] For example, as shown in (1) in FIG. 28, the child view does not completely occupythe layout container. After the stretching capability of the layout container is enabled, when thedimension of the layout container changes, the child view in the layout container is stretched in aspecified direction.

[00466] In some examples, an attribute value of horizontal stretching capability enablement ofthe layout container is set to true, and the width of the child view is set to "match_parent". Ahorizontal inner margin is further set, for example, a left inner margin and / or a right inner margin.Therefore, as shown in (2) in FIG. 28, when the dimension of the layout container changes, ahorizontal inner margin of the child view is kept as a specified value, and the child view ishorizontally stretched. In other words, the width of the child view adaptively changes with thewidth of the layout container. Certainly, the developer may also set any horizontal inner margin.In this case, the other inner margin that is not set is 0 dp by default.

[00467] It should be noted that, for a vertical change of the child view, refer to thedescriptions of the related content in FIG. 27. Details are not described herein again.

[00468] In some other examples, an attribute value of vertical stretching capabilityenablement of the layout container is set to true, and the height of the child view is set to"match_parent". A vertical inner margin is further set, for example, an upper inner margin and / ora lower inner margin. Therefore, as shown in (3) in FIG. 28, when the dimension of the layoutcontainer changes, a vertical inner margin of the child view is kept as a specified value, and thechild view is vertically stretched. In other words, the width of the child view adaptively changeswith the height of the layout container. Certainly, the developer may also set any vertical innermargin. In this case, the other inner margin that is not set is 0 dp by default.

[00469] It should be noted that, for a horizontal change of the child view, refer to thedescriptions of the related content in FIG. 27. Details are not described herein again.

[00470] In some other examples, an attribute value of horizontal stretching capabilityenablement of the layout container is set to true, the width of the child view is set to"match_parent", and the horizontal inner margin is set; and each attribute value of verticalstretching capability enablement of the layout container is set to true, the height of the child viewis set to "match_parent", and the vertical inner margin is set. In this case, when the dimension ofthe layout container changes, the child view is horizontally and vertically stretched. In otherwords, as shown in (4) in FIG. 28, the height of the child view adaptively changes with theheight of the layout container, and the width of the child view adaptively changes with the widthof the layout container.

[00471] It can be learned that, by setting the inner margin of the layout container, it is ensuredthat a view in the layout container keeps a specific distance from an edge of the layout container,so that different display requirements can be met. For example, by ensuring that the view in thelayout container keeps a specific distance from the edge of the layout container, the displayinterface can present a magazine-like layout, for example, present a large white space, so that thedisplay interface presents a magazine-like reading sense. This improves visual experience of theuser.

[00472] In some other embodiments, in addition to the stretching capability of the layoutcontainer in the specified direction and the inner margin value in the specified direction, amaximum / minimum value may be further set for the dimension of the layout container, forexample, a maximum width, a minimum width, a maximum height, and a minimum height. Themaximum width means a maximum value that can be reached by a sum of horizontal widths ofall child views in the layout container (including horizontal spacings between the child views).The minimum width means a minimum value that can be reached by a sum of horizontal widthsof all child views in the layout container (including horizontal spacings between the child views).The maximum height means a maximum value that can be reached by a sum of vertical heightsof all child views in the layout container (including vertical spacings between the child views).The minimum height means a minimum value that can be reached by a sum of vertical widths ofall child views in the layout container (including vertical spacings between the child views). Itshould be noted that, in a stretching process of the child view, when a dimension sum of all thechild views conflicts with a maximum / minimum dimension value that is set by the layoutcontainer, an actual stretching proportion of the child view may be determined based on themaximum / minimum dimension value. In some other examples, if the maximum / minimumdimension value of the layout container is not set, a default value may also be used. For example,the maximum width is infinite by default, the minimum width is 0 dp by default, the maximumheight is infinite by default, and the minimum height is 0 dp by default. Certainly, the defaultvalue may alternatively be another value. This is not limited in this embodiment of thisapplication.

[00473] It can be learned that setting the maximum / minimum dimension value of the layoutcontainer can prevent a view in the layout container from being excessively scaled up or scaleddown in a specified direction. For example, avoiding excessive scale-up in the specified directioncan ensure that view information in the layout container is not lost. For example, an image viewis not distorted or deformed. Avoiding excessive scale-down in the specified direction can ensurethat view content in the layout container does not overlap and therefore can prevent a displayeffect from being affected.

[00474] It should be noted that, when the child view is a View, and when running theapplication, the electronic device stretches the View in a specified direction based on an actualdimension of the layout container, and the inner margin and the maximum / minimum dimensionvalue of the layout container, and displays the View. When the view is a ViewGroup, and whenrunning the application, the electronic device stretches the ViewGroup in a specified direction byusing a same method. It should be noted that, for a View nested in a ViewGroup or a ViewGroup,an attribute corresponding to the ViewGroup is used for layout. For example, if a stretchingcapability is also enabled for the ViewGroup, a method corresponding to the stretching capabilityis used to draw the View nested in the ViewGroup or the ViewGroup. For another example, if astretching capability is not enabled for the ViewGroup, a method corresponding to the stretchingcapability is not used to draw the View nested in the ViewGroup or the ViewGroup. In otherwords, the stretching capability that is set for the layout container may be applied to a child viewstored in the layout container, but cannot be applied to a View or a ViewGroup nested in thechild view.

[00475] The following provides an example of one layout file (an XML file). A layoutcontainer with a stretching capability enabled is set in the layout file, and the layout containerincludes one child view (a button view). / * layout stretching example * / <com.huawei.adaptive stretching layoutxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto"android:layout_height="300dp" / / set a height of the layout containerandroid:layout_width="130dp" / / set a width of the layout containerapp: horizontal stretching capability enablement="true" / / enable a horizontalstretching capability of the layout containerapp: vertical stretching capability enablement="true" / / enable a verticalstretching capability of the layout containerandroid: left inner margin="25dp" / / set a left inner margin of the layoutcontainerandroid: upper inner margin="25dp" / / set an upper inner margin of thelayout containerandroid: right inner margin="25dp" / / set a right inner margin of thelayout containerandroid: lower inner margin="25dp" / / set a lower inner margin of thelayout containerapp: maximum width="400dp" / / set a maximum width of the layoutcontainerapp: maximum height="400dp" / / set a maximum height of the layoutcontainerapp: minimum width="100dp" / / set a minimum width of the layoutcontainerapp: minimum height="100dp"> / / set a minimum height of the layoutcontainer<Button / / set a child view-button viewandroid:layout_width="match_parent" / / set a width of the child viewandroid:layout_height="match_parent" / / set a height of the childviewandroid:text="Button" / >< / com.huawei.adaptive stretching layout>

[00476] To better understand an adaptive layout effect implemented by using the stretchingcapability in this embodiment of this application, an example in which head units havingdifferent screen dimensions display music play interfaces is used for description herein. It shouldbe noted that layout files corresponding to the music play interfaces are the same, that is, layoutparameters of Views and ViewGroups on the music play interfaces are the same.

[00477] As shown in (1) in FIG. 29, an interface 2901 is an example of a music play interfacedisplayed by a head unit 1. On the interface 2901, a horizontal stretching capability is set for alayout container 2900. The layout container 2900 stores a plurality of button views, for example,a button view 2910, a button view 2911, and a button view 2913. A width of each of these buttonviews is set to "match parent", and a height is set to a fixed value. In this case, when a horizontaldimension of the layout container 2900 changes, these button views are horizontally stretched.

[00478] For example, as shown in (2) in FIG. 29, an interface 2902 is an example of a musicplay interface displayed by a head unit 2. Compared with a width of a screen dimension of thehead unit 1, a width of a screen dimension of the head unit 2 is increased, and a width of thelayout container 2900 is also increased. Therefore, when displaying the music play interface, thehead unit 2 horizontally stretches the button views (such as the button view 2910, the buttonview 2911, and the button view 2913) in the layout container 2900. In some examples, as thewidth of the button view increases, resources (for example, text) displayed in the button viewmay also adaptively increase. The height of each of these button views remains at a fixedspecified value.

[00479] The foregoing embodiment is a solution in which the developer designs an adaptivedisplay interface layout by setting an attribute value related to a stretching capability of a Viewor a ViewGroup in a layout file (for example, an XML file). Alternatively, an attribute valuerelated to a stretching capability of a View or a ViewGroup may be set in a Java source code fileby adding a call interface.

[00480] Table 10 shows an example of an interface corresponding to the attribute valuerelated to the stretching capability of the View or the ViewGroup.Table 10

[00481] The meanings of the stretching capability are described in detail above. A developermay configure a layout file based on a layout design of each display interface in an applicationwith reference to a stretching capability, another adaptive layout capability, and a basic layoutcapability (for example, an Android native attribute), pack the layout file, other source code andresources, and the like of the application into an installation package (for example, an APK file),and release the installation package to an application market. An electronic device downloads theinstallation package from the application market, and installs the application. The followingdescribes in detail a solution of implementing adaptive layout based on the foregoing layout filewhen the electronic device runs the application.

[00482] Specifically, the mobile phone performs a measurement procedure shown in FIG.30A(1) and FIG. 30A(2) for each layout container in the layout file. The method specificallyincludes the following steps.

[00483] S3001: Obtain a width measurement mode and an initial width of the layoutcontainer.

[00484] Generally, the measurement mode and the initial width of the layout container aredetermined by a MeasureSpec parameter transferred from a parent layout container. Herein,MeasureSpec indicates a 32-bit integer. The most significant 2 bits indicate the measurementmode (SpecMode), and the least significant 30 bits indicate a specification size (SpecSize) in aspecific measurement mode, that is, the initial width.

[00485] S3002: Obtain a maximum / minimum width value of the layout container based on thelayout file.

[00486] S3003: Determine whether a horizontal stretching capability of the layout container isenabled; and if yes, perform step S3004; otherwise, perform step S3011.

[00487] S3004: Update the maximum / minimum width value to a maximum / minimum widthvalue obtained after maximum / minimum value filtering.

[00488] For example, the mobile phone determines whether a maximum width of the layoutcontainer that is set by the developer in the layout file is greater than or equal to a minimumwidth of the layout container. If yes, the mobile phone determines to use the specified maximumand minimum widths of the layout container. In other words, the specified maximum andminimum widths of the layout container are maximum and minimum width values obtained aftermaximum / minimum value filtering.

[00489] S3005: Determine whether the initial width of the layout container is greater than themaximum width; and if yes, perform step S3006; otherwise, perform step S3007.

[00490] S3006: Modify a width of the layout container to the maximum width.

[00491] S3007: Determine whether the initial width of the layout container is less than theminimum width; and if yes, perform step S3008; otherwise, perform step S3009.

[00492] S3008: Modify a width of the layout container to the minimum width.

[00493] S3009: Perform measurement by using an original width measurement mode and anadjusted width of the layout container.

[00494] In other words, in this case, the measurement mode determined in step S3001 and thewidth of the layout container that is adjusted in step S3006 or step S3008 are still used formeasurement.

[00495] S3010: Set a width of a child view in the layout container to match_parent.

[00496] In other words, the width of the child view in the layout container changes with thewidth of the layout container.

[00497] S3011: Obtain a height measurement mode and an initial width of the layoutcontainer.

[00498] Likewise, the measurement mode and the initial height of the layout container aredetermined by a MeasureSpec parameter transferred from a parent layout container. Herein,MeasureSpec indicates a 32-bit integer. The most significant 2 bits indicate the measurementmode (SpecMode), and the least significant 30 bits indicate a specification size (SpecSize) in aspecific measurement mode, that is, the initial height.

[00499] S3012: Obtain a maximum / minimum height value of the layout container based onthe layout file.

[00500] S3013: Determine whether a vertical stretching capability of the layout container isenabled; and if yes, perform step S3014; otherwise, end the procedure.

[00501] S3014: Update the maximum / minimum height value to a maximum / minimum heightvalue obtained after maximum / minimum value filtering.

[00502] For example, the mobile phone determines whether a maximum height of the layoutcontainer that is set by the developer in the layout file is greater than or equal to a minimumheight of the layout container. If yes, the mobile phone determines to use the specified maximumand minimum heights of the layout container. In other words, the specified maximum andminimum heights of the layout container are maximum and minimum height values obtainedafter maximum / minimum value filtering.

[00503] S3015: Determine whether the initial height of the layout container is greater than themaximum height; and if yes, perform step S3016; otherwise, perform step S3017.

[00504] S3016: Modify a height of the layout container to the maximum height.

[00505] S3017: Determine whether the initial height of the layout container is less than theminimum height; and if yes, perform step S3018; otherwise, perform step S3019.

[00506] S3018: Modify a height of the layout container to the minimum height.

[00507] S3019: Perform measurement by using an original height measurement mode and anadjusted height of the layout container.

[00508] In other words, in this case, the measurement mode determined in step S3011 and thewidth of the layout container that is adjusted in step S3016 or step S3018 are still used formeasurement.

[00509] S3020: Set a height of a child view in the layout container to match_parent.

[00510] In other words, the height of the child view in the layout container changes with theheight of the layout container.

[00511] It should be noted that the foregoing measurement procedure is merely an example. Asequence of performing some steps may be changed, or some steps may be combined, simplified,or the like. For example, the height of the layout container may alternatively be measured beforethe width of the layout container is measured, that is, steps S3011 to S3020 may be performedbefore or when steps S3001 to 810 are performed. For another example, determining whether aninitial dimension of the layout container is greater than a maximum dimension and determiningwhether an initial dimension of the layout container is less than a minimum dimension may besimultaneously performed, or determining sequences may be exchanged. Steps of the extendedmeasurement procedure are not limited in this embodiment of this application.

[00512] It can be understood that, when electronic devices (for example, a mobile phone and atablet computer) having different screen dimensions use a same layout file (including a layoutcontainer provided with a stretching capability), according to the measurement procedure in FIG.30A(1) and FIG. 30A(2), application interfaces finally drawn may present different layouteffects.

[00513] For example, a screen width of the mobile phone is 720 pixels, and a screen width ofthe tablet computer is 1280 pixels. Both the mobile phone and the tablet computer use a sameinstallation package to install a music application. A layout file corresponding to a play page ofthe music application includes a layout container configured to display lyrics, and the layoutcontainer enables a horizontal stretching capability. In addition, the layout container includes onehorizontally arranged text view, configured to display lyrics. Left and right inner margins of thelayout container each are 20 pixels, a maximum width is 1000 pixels, and a minimum width is500 pixels.

[00514] In this case, when the mobile phone draws the play page of the music application andexecutes the measurement procedure in FIG. 30A(1) and FIG. 30A(2), a width of the layoutcontainer is calculated as follows: screen width - left and right inner margins = 720 - 20 - 20 =680 pixels. This meets requirements of the maximum and minimum widths of the layoutcontainer. Further, because a width of a text view in the layout container is match-parent, thewidth of the text view in the layout container is 680 pixels. The mobile phone displays aninterface 301 shown in (1) in FIG. 30B, where a width of a text view in a layout container 302 is680 pixels. If the layout container is further provided with a vertical stretching capability, similarto the method for calculating the width of the layout container, the layout container and theheight of the text view in the layout container may be calculated. Details are not described hereinagain.

[00515] When the tablet computer draws the play page of the music application and executesthe measurement procedure in FIG. 30A(1) and FIG. 30A(2), a width of the layout container iscalculated as follows: screen width - left and right inner margins = 1280 - 20 - 20 = 1240 pixels.Because the calculated width (1240 pixels) of the layout container is greater than the specifiedmaximum width (1000 pixels), the width of the layout container is adjusted to the specifiedmaximum width 1000 pixels. Further, because a width of a text view in the layout container ismatch-parent, the width of the text view in the layout container is 1000 pixels. The tabletcomputer displays an interface 303 shown in (2) in FIG. 30B, where a width of a text view in alayout container 304 is 1000 pixels. If the layout container is further provided with a verticalstretching capability, similar to the method for calculating the width of the layout container, thelayout container and the height of the text view in the layout container may be calculated. Detailsare not described herein again.

[00516] In conclusion, in an application development phase, a developer of an application setsan attribute of an adaptive layout capability (for example, an extension capability, a proportioncapability, an equalization capability, a hiding capability, or a stretching capability) in a View anda ViewGroup on a display interface in a layout file. After installing the application, electronicdevices having different screen parameters may automatically adjust, with reference to the screenparameters of the electronic devices, dimensions and / or layouts of a View and a ViewGroup ineach layout container based on the attribute of the adaptive layout capability of the View and theViewGroup in the layout file, so as to implement adaptive display interface layouts. In this way,the developer needs to design only one layout file, so that display requirements of the electronicdevices having different screen parameters can be met, and development costs and maintenancecosts of the developer can be reduced.

[00517] In addition, compared with a solution in which an application installation packageneeds to carry a plurality of layout files, this solution in which an application installationpackage carries one layout file increases traffic costs and time costs of downloading anapplication installation package by the electronic device. In addition, after installing theapplication, the electronic device does not need to store another redundant layout file. Thisincreases storage space utilization of the electronic device.

[00518] It can be understood that a plurality of adaptive layout capabilities extended in thisembodiment of this application may be used in combination with each other. For example,different adaptive layout capability attributes are set for different objects (Views or ViewGroups)on a same application interface, or two or more adaptive layout capability attributes are set for asame object. It should be noted that, when two or more adaptive layout capability attributes areset for a same object, an adaptive layout capability of the layout container may be enabled ordisabled for each adaptive layout capability, or a plurality of adaptive layout capabilities of thelayout container may be uniformly enabled or disabled for a plurality of adaptive layoutcapabilities. This application imposes no limitation on specific implementation. It can beunderstood that, in an actual application development process, in addition to a case in which aconflict occurs during combination, the foregoing adaptive layout capabilities may be randomlycombined according to an actual requirement. For example, the stretching capability may becombined with any one of the hiding capability, the proportion capability, the equalizationcapability, and a wrapping capability; and the scaling capability may be combined with any oneof the hiding capability, the proportion capability, the equalization capability, and the wrappingcapability. Some examples of several adaptive layout capability combinations may be providedherein.

[00519] 1. Stretching capability + Equalization capability

[00520] For example, the stretching capability and the equalization capability are set for asame object. As shown in (1) in FIG. 31, an interface 3101 is a music play interface. On theinterface 3101, a horizontal stretching capability is set for a layout container 3100. The layoutcontainer 3100 stores a plurality of child layout containers, for example, a child layout container3110, a child layout container 3111, and a child layout container 3113. A width of each of thesechild layout containers is set to "match parent", and a height is set to a fixed value. In addition,the layout container 3100 is further provided with a vertical equalization capability.

[00521] For example, as shown in (2) in FIG. 31, an interface 3103 is an example of a musicplay interface displayed by a head unit 2. Compared with a width of a screen dimension of thehead unit 1 shown in (1) in FIG. 31, a width of a screen dimension of the head unit 2 is increased,and a width of the layout container 3100 is also increased. Therefore, when displaying the musicplay interface, the head unit 2 horizontally stretches the child layout containers (for example, thechild layout container 3110, the child layout container 3111, and the child layout container 3113)in the layout container 3100. In addition, compared with a height of the screen dimension of thehead unit 1, a height of the screen dimension of the head unit 2 is increased, and a width of thelayout container 3100 is also increased. However, the height of each of the child layoutcontainers in the layout container 3100 remains a fixed value. Because the layout container 3100is provided with the vertical equalization capability, spacings between these child layoutcontainers in the layout container 3100 are increased, and the spacings between the child layoutcontainers keep equal.

[00522] 2. Stretching capability + Hiding capability

[00523] For example, the stretching capability and the hiding capability are set for a sameobject. The music play interface shown in (1) in FIG. 31 is still used as an example. On theinterface 3101, a horizontal stretching capability is set for a layout container 3100. The layoutcontainer 3100 stores a plurality of child layout containers, for example, a child layout container3110, a child layout container 3111, and a child layout container 3113. A width of each of thesechild layout containers is set to "match parent", and a height is set to a fixed value. In addition,the layout container 3100 is further provided with a vertical hiding capability.

[00524] For example, as shown in (3) in FIG. 31, an interface 3104 is an example of a musicplay interface displayed by a head unit 3. Compared with a width of a screen dimension of thehead unit 1 shown in (1) in FIG. 31, a width of a screen dimension of the head unit 3 is increased,and a width of the layout container 3100 is also increased. Therefore, when displaying the musicplay interface, the head unit 3 horizontally stretches the child layout containers (for example, thechild layout container 3110, the child layout container 3111, and the child layout container 3113)in the layout container 3100. In addition, compared with a height of the screen dimension of thehead unit 1, a height of the screen dimension of the head unit 3 is increased, and a width of thelayout container 3100 is also increased. However, the height of each of the child layoutcontainers in the layout container 3100 remains a fixed value. Because the layout container 3100is provided with the vertical hiding capability, as the height of the layout container 3100increases, more child layout containers may be displayed, for example, the child layout container3113. On the interface 3101, when the screen of the head unit 1 is relatively small, it may beconsidered that the child layout container 3113 is hidden.

[00525] In conclusion, electronic devices having different screen parameters draw differentdisplay interfaces based on a same layout file. In other words, the electronic devices havingdifferent screen parameters may adaptively perform display interface layout adjustment based onthe layout file, so as to meet different display requirements.

[00526] 3. Stretching capability + Scaling capability + Hiding capability

[00527] For example, different adaptive capabilities such as the stretching capability, thescaling capability, and the hiding capability are separately set for different objects on a sameinterface. FIG. 32(1) shows a play interface 3201 displayed when a mobile phone runs a musicapplication. The play interface 3201 includes an image view 3202 (configured to display analbum cover), a text view 3203 (configured to display song information), and a button viewgroup 3204 (including button views such as "Previous", "Play", "Next", and "Playlist"). Theimage view 3202 is provided with a scaling capability (a horizontal available space proportionand a vertical available space proportion), the text view 3203 is provided with a stretchingcapability, and the button view group 3204 is provided with a hiding capability.

[00528] FIG. 32(2) shows a play interface 3205 displayed when a tablet runs a musicapplication. It can be learned that a screen of the tablet is wider than but is lower than a screen ofthe mobile phone. Therefore, the image view 3202 needs to be scaled down based on the scalingcapability corresponding to the image view 3202. Because the text view 3203 has the stretchingcapability, when the width of the screen of the tablet is increased, the width of the text view 3203is also increased. When the width of the screen of the tablet is increased, a display width of thebutton view group 3204 is increased, and more button views may be displayed, that is, somehidden button views (for example, "Favorites") are displayed. In other words, the scalingcapability may implement scaling of the image view when the width / height of the screenchanges. In addition, the stretching capability implements adaptive stretching or shrinking of thetext view when the width / height of the screen changes, and the hiding capability implementsadaptive increase or decrease of a quantity of displayed button views when the width / height ofthe screen changes.

[00529] 4. Equalization capability + Wrapping capability

[00530] A browsing interface of a gallery application is used as an example for description.

[00531] FIG. 33(1) shows a browsing interface displayed when a tablet runs the galleryapplication. The browsing interface includes one layout container, and the layout containerincludes a plurality of image views (configured to display a thumbnail of a photo or a video).The layout container is provided with a wrapping capability and an equalization capability (forexample, a second-type equalization capability). In this case, widths of the plurality of imageviews are just a wrapping reference value.

[00532] FIG. 33(2) shows a browsing interface displayed when a mobile phone runs thegallery application. First, the mobile phone determines a quantity of rows of the layout containerand a quantity of image views displayed in each row based on a wrapping reference value ofeach image view in the layout container. For example, the mobile phone determines that amaximum of three image views are displayed in each row on the mobile phone. In this case, itmay be determined that the five image views need to be displayed in two rows on the mobilephone. In addition, because the layout container is further provided with the equalizationcapability, when displaying the image views in each row, the mobile phone further ensures thatthe image views in each row have same spacings. It may be noted that, on the mobile phone, aquantity of image views displayed in the second row is less than a quantity of gallery viewsdisplayed in the first row, and a spacing between image views in the second row is greater than aspacing between image views in the first row. By comparing the browsing interface in FIG. 33(2)with the browsing interface in FIG. 33(1), it can be learned that, although a width of the mobilephone is smaller than that of the tablet, the quantity of image views displayed in each row isreduced, and the spacing between image views in each row is adaptively adjusted.

[00533] Alternatively, FIG. 33(3) shows another browsing interface displayed when a tabletruns a gallery application. A difference from the browsing interface shown in FIG. 33(2) lies in amethod for displaying the image views in the second row. On the browsing interface shown inFIG. 33(2), the tablet recalculates a spacing between adjacent child views based on a quantity ofchild views actually included in the second row, a width of each child view, and a specifiedequalization type, and performs display based on the recalculated spacing. On the browsinginterface shown in FIG. 33(3), the tablet directly displays the child views in the second rowbased on the calculated spacing in the first row. In other words, a spacing between adjacent childviews in the second row is equal to or approximate to a spacing between adjacent child views inthe first row.

[00534] It can be learned that a developer may not need to pay attention to a screen dimensionof an electronic device, and does not need to pay attention to a quantity of image views that canbe displayed in one row, but directly use a wrapping capability and an equalization capability toenable the electronic device to adaptively perform layout adjustment and adaptively adjust aspacing between image views. This can implement a grid effect.

[00535] 5. Equalization capability + Hiding capability

[00536] A play interface of a music application is used as an example for description.

[00537] Herein, (1) in FIG. 34 shows a play interface displayed when a tablet runs the musicapplication. The play interface includes one layout container, and the layout container includes aplurality of image button views ("Favorites", "Previous", "Play", "Next", and "Playlist"). Thelayout container is provided with an equalization capability (for example, a second-typeequalization capability) and a hiding capability. A hiding priority of each of "Previous", "Play",and "Next" is lower than that of "Playlist", and the hiding priority of "Playlist" is lower than thatof "Favorites".

[00538] Herein, (2) in FIG. 34 shows a play interface displayed when a mobile phone runs themusic application. Compared with the tablet, a width of the mobile phone is reduced, andcorrespondingly a width of the layout container is also reduced. In this case, the mobile phonefirst determines, based on the width of the layout container and a width of each icon button view,that the layout container cannot display all icon button views. The mobile phone determines,based on hiding priorities of the icon button views, an icon button view that needs to be hidden.First, the mobile phone hides the icon button view of "Favorites", and determines that theremaining four icon button views may be displayed in the layout container. Then, the mobilephone determines spacings between the four icon button views based on dimensions of theremaining four icon button views and a dimension of the layout container. If the layout containercannot display the four icon button views, the icon button view that further needs to be hidden isfurther determined, and so on.

[00539] An example of a layout file in which both an equalization capability and a hidingcapability are enabled is provided herein.<hwLayoutxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto" / * omit other configurations * / android:orientation="horizontal" / / set a layout orientation of the layoutcontainerapp: equalization capability enablement="true" / / enable an equalizationcapability of the layout containerapp: equalization type="second type" / / set as a second-type equalizationcapabilityapp: hiding capability enablement="true" / / enable a hiding capability of thelayout container<ImageButton / / set an icon button view of the layout container / * omit other configurations * / android:src="@drawable / trends_ic_favorite"app: hiding priority="3" / > / / set a hiding priority of the first icon button viewof the layout container<ImageButton / * omit other configurations * / android:src="@drawable / trends_ic_previous"app: hiding priority="1" / > / / set a hiding priority of the second icon button viewof the layout container<ImageButton / * omit other configurations * / android:src="@drawable / trends_ic_pause"app: hiding priority="1" / > / / set a hiding priority of the third icon button view ofthe layout container<ImageButton / * omit other configurations * / android:src="@drawable / trends_ic_next"app: hiding priority="1" / > set a hiding priority of the fourth icon button view ofthe layout container<ImageButton / * omit other configurations * / android:src="@drawable / trends_ic_list"app: hiding priority="2" / > set a hiding priority of the fifth icon button view ofthe layout container< / hwLayout>

[00540] 6. Equalization capability + Scaling capability

[00541] A browsing interface of a gallery application is still used as an example fordescription.

[00542] FIG. 35(1) shows a browsing interface displayed when a mobile phone runs thegallery application. The gallery application includes one layout container, and the layoutcontainer includes a plurality of image views (configured to display a thumbnail of a photo or avideo). The layout container is provided with a scaling capability, and a horizontal availablespace proportion and a vertical available space proportion are set for each image view. Thelayout container is further provided with an equalization capability (for example, a second-typeequalization capability).

[00543] FIG. 35(2) shows a browsing interface displayed when a tablet runs the galleryapplication. Compared with the mobile phone, the tablet has a wider width. The image view isscaled up based on the width of the layout container, and the horizontal available spaceproportion and the vertical available space proportion of the image view. After a width of thescaled-up image view is determined, a spacing between two adjacent image views is determinedbased on an available space of the layout container.

[00544] 7. Hiding capability + Wrapping capability

[00545] A browsing interface of a gallery application is used as an example for description.

[00546] FIG. 36(1) shows a browsing interface displayed when a tablet runs the galleryapplication. The browsing interface includes one layout container, and the layout containerincludes a plurality of image views (configured to display a thumbnail of a photo or a video): animage view A to an image view E. The layout container is provided with a wrapping capabilityand a hiding capability. The image views A and E have the highest hiding priority, the imageviews B and D have the second highest hiding priority, and the image view C has the lowesthiding priority. In this case, widths of the plurality of image views are just a wrapping referencevalue.

[00547] FIG. 36(2) is a schematic diagram of an interface in which the tablet displays twowindows on split screens. The left window is configured to display the browsing interface of thegallery application. The right window is configured to display the play interface of the musicapplication. Because a dimension of the window configured to display the browsing interface ofthe gallery application is reduced, the tablet is triggered to display the layout container in awrapping manner. It is determined, based on the wrapping reference value of each image view inthe layout container, that only one image view can be displayed in each row. In this case, the fiveimage views are exactly vertically displayed on the interface shown in FIG. 36(2). If a height ofthe window that is used by the tablet to display the browsing interface of the gallery applicationis insufficient to display the five image views, the tablet is triggered to hide the five image viewsbased on the hiding priorities. On an interface shown in FIG. 36(3), the image view A and theimage view E that have the highest hiding priority are not displayed.

[00548] The following provides an example of one layout file (an XML file). A layoutcontainer with a hiding capability enabled is set in the layout file, and the layout containerincludes four child views: four image views.<hwLayoutxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto" / * omit other configurations * / android:orientation="horizontal"app: vertical hiding capability enablement="true" / / enable a vertical hidingcapabilityapp: wrapping capability enablement="true" / / enable a wrappingcapabilityapp: wrapping alignment mode="end"> / / set the wrapping alignment mode. ForChinese and English, "end" corresponds to right alignment<ImageView / / set a child view 1 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="3" / / set a vertical hiding priority of thechild view 1app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 1<ImageView / / set a child view 2 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="2" / / set a vertical hiding priority of thechild view 2app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 2<ImageView / / set a child view 3 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="1" / / set a vertical hiding priority of thechild view 3app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 3<ImageView / / set a child view 4 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="2" / / set a vertical hiding priority of thechild view 4app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 4<ImageView / / set a child view 5 in the layout container-image view / * omit other configurations * / app:layout_vertical hiding priority="3" / / set a vertical hiding priority of thechild view 5app: wrapping reference width="90dp" / > / / set a wrapping referencevalue of the wrapped child view 5< / hwLayout>

[00549] 8. Proportion capability + Scaling capability

[00550] A browsing interface of a gallery application is used as an example for description.

[00551] FIG. 37(1) shows a browsing interface displayed when a mobile phone runs thegallery application. The gallery application includes one layout container, and the layoutcontainer includes a plurality of image views (configured to display a thumbnail of a photo or avideo). The layout container is provided with a scaling capability (a horizontal available spaceproportion and a vertical available space proportion are not set for each image view). In addition,the layout container is further provided with a proportion capability (for example, a proportion ina horizontal direction, for example, 33.33%).

[00552] FIG. 37(2) shows a browsing interface displayed when a tablet runs the galleryapplication. It can be learned that all image views evenly occupy an available space in ahorizontal direction of the tablet (a width of each image view is 1 / 3 of a total width of the tablet).The scaling capability of each image view enables each image view to be scaled to occupy theavailable space in the horizontal direction. In other words, the proportion capability controls ahorizontal size of each image view. The scaling capability ensures that each image view is scaledbased on an aspect ratio, to avoid image distortion.

[00553] 9. Proportion capability + Scaling capability + Wrapping capability

[00554] A browsing interface of a gallery application is still used as an example fordescription.

[00555] FIG. 38(1) shows a browsing interface displayed when a tablet runs the galleryapplication. The gallery application includes one layout container, and the layout containerincludes a plurality of image views (configured to display a thumbnail of a photo or a video).The layout container is provided with a scaling capability (a horizontal available spaceproportion and a vertical available space proportion are not set for an image view). In addition,the layout container is provided with a horizontal proportion capability and a horizontalwrapping capability.

[00556] FIG. 38(2) shows a browsing interface displayed when a mobile phone runs thegallery application. First, the mobile phone determines a quantity of image views displayed ineach row based on a wrapping reference value of each image view in the layout container. Forexample, the mobile phone determines that only three image views are displayed in each row onthe mobile phone. Then, widths of the three image views in the first row are determined based onthe horizontal proportion capability, and then a shape of the image view is kept for scaling basedon the scaling capability of the image view. For a horizontal proportion of an image view inanother row, refer to the width of the image view in the first row. By comparing the browsinginterface in FIG. 38(2) with the browsing interface in FIG. 38(1), it can be learned that, althoughthe width of the mobile phone is smaller than that of the tablet, the image view in each row isenlarged.

[00557] The following is an example of an XML file that combines the scaling capability, thewrapping capability, and the proportion capability.<hwLayoutxmlns:android="http: / / schemas.android.com / apk / res / android"xmlns:app="http: / / schemas.android.com / apk / res-auto" / * omit other configurations * / app: proportion capability enabled / disabled="true" / / enable a proportioncapability of the layout containerapp: wrapping capability enabled / disabled="true"app: wrapping alignment mode="start"> / / set the wrapping alignmentmode. In Chinese or English, "start" indicates left alignment. In Arabic, "start" indicates rightalignment<hwLayoutandroid:layout_height="match_parent"android:layout_width="match_parent"app: wrapping reference width="80dp" / / set a wrapping referencevalueandroid:gravity="center_horizontal"app: scaling capability enabled / disabled="true"> / / enable a scalingcapability of the layout container<ImageView / * omit other configurations * / / >< / hwLayout><hwLayoutandroid:layout_height="match_parent"android:layout_width="match_parent"app: wrapping reference width="80dp" / / set a wrapping reference valueandroid:gravity="center_horizontal"app: scaling capability enabled / disabled="true"><ImageView / * omit other configurations * / / >< / hwLayout><hwLayoutandroid:layout_height="match_parent"android:layout_width="match_parent"app: wrapping reference width="80dp" / / set a wrapping referencevalueandroid:gravity="center_horizontal"app: scaling capability enabled / disabled="true"><ImageView / * omit other configurations * / / >< / hwLayout><hwLayoutandroid:layout_height="match_parent"android:layout_width="match_parent"app: wrapping reference width="80dp" / / set a wrappingreference valueandroid:gravity="center_horizontal"app: scaling capability enabled / disabled="true"><ImageView / * omit other configurations * / / >< / hwLayout><hwLayoutandroid:layout_height="match_parent"android:layout_width="match_parent"app: wrapping reference width="80dp" / / set a wr...

Claims

1. An application interface layout method, wherein an electronic device installs an application installation package of a first application, the application installation package comprises a first layout file, the first layout file indicates N child views and an enabled preset capability, and N is a positive integer; the preset capability comprises one or more of an extension capability, a proportion capability, an equalization capability, a stretching capability, and a hiding capability; and the method comprises: receiving, by the electronic device, a first operation performed by a user on a first interface; in response to the received first operation, determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability, wherein the device parameter of the electronic device comprises at least one of a screen type value, a screen dimension value, or a running status value of the electronic device, and the attribute values of the N child views are used to indicate sizes and locations of the N child views on a second interface; and displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views.

2. The method according to claim 1, wherein the first layout file comprises a preset parameter corresponding to the preset capability; and the determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability comprises: determining, by the electronic device, the attribute values of the N child views based on the device parameter of the electronic device, the preset capability, and the preset parameter.

3. The method according to claim 1 or 2, wherein a running status of the electronic device comprises one or more of a landscape / portrait state, a screen splitting state, and a folding state of the electronic device.

4. The method according to any one of claims 1 to 3, wherein the first operation is any one of an operation of starting the first application, an operation of jumping to the second interface, or an operation of switching the running status of the electronic device.

5. The method according to any one of claims 1 to 4, wherein the preset capability is the extension capability, the first layout file indicates that the N child views are arranged in a first orientation of a first layout container, and the first orientation is a horizontal orientation or a vertical orientation; the determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability comprises: determining, by the electronic device, a dimension of the first layout container in the first orientation based on the device parameter; and determining N1 child views and the (N1+1)th child view in the N child views based on the dimension of the first layout container in the first orientation and dimensions of the N child views in the first orientation, wherein N1 is less than N; and the displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views comprises: completely displaying, by the electronic device, the N1 child views and partially displaying the (N1+1)th child view on the second interface based on the attribute values of the N child views.

6. The method according to claim 5, wherein the method further comprises: receiving a second operation performed by the user on the second interface; and displaying a third interface in response to the second operation, wherein the third interface displays the (N1+2)th child view in the N child views.

7. The method according to any one of claims 1 to 4, wherein the preset capability is the proportion capability, the first layout file indicates proportions of arranging the N child views and a first child view in the N child views in a first orientation of a first layout container, and the first orientation is a horizontal orientation or a vertical orientation; the determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability comprises: determining, by the electronic device, a dimension of the first layout container in the first orientation based on the device parameter; and determining a dimension of the first child view in the first orientation based on the dimension of the first layout container in the first orientation and the proportion of the first child view; and the displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views comprises: displaying, by the electronic device, the first child view on the second interface based on the attribute values of the N child views.

8. The method according to any one of claims 1 to 4, wherein the preset capability is the equalization capability, and the first layout file indicates that the N child views are arranged in a first orientation of a first layout container and indicates a dimension of each of the N child views in the first orientation and an inner margin of the first layout container in the first orientation; the determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability comprises: determining, by the electronic device, a dimension of the first layout container in the first orientation based on the device parameter; and determining a first spacing based on the dimension of the first layout container in the first orientation, the dimension of each of the N child views in the first orientation, and the inner margin of the first layout container in the first orientation, wherein the first spacing is a spacing between two adjacent child views, and two adjacent child views have an equal spacing; and the displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views comprises: displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views, wherein a spacing between two adjacent child views is the first spacing.

9. The method according to any one of claims 1 to 4, wherein the preset capability is the hiding capability, and the first layout file indicates that the N child views are arranged in a first orientation of a first layout container and indicates a dimension of each of the N child views in the first orientation and an inner margin of the first layout container in the first orientation; the determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability comprises: determining, by the electronic device, a dimension of the first layout container in the first orientation based on the device parameter; and determining M child views from the N child views when a first dimension is greater than a second dimension, wherein M is an integer less than N, the first dimension is determined based on the dimensions of the N child views in the first orientation, and the second dimension is determined based on the dimension of the first layout container in the first orientation and the inner margin of the first layout container in the first orientation; and the displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views comprises: displaying, by the electronic device, the M child views on the second interface based on the attribute values of the N child views.

10. The method according to claim 9, wherein the first layout file further indicates hiding priorities of the N child views, and the determining M child views from the N child views when a first dimension is greater than a second dimension comprises: determining the M child views from the N child views based on the hiding priorities of the N child views when the first dimension is greater than the second dimension.

11. The method according to any one of claims 1 to 4, wherein the preset capability is the stretching capability, and the first layout file indicates that the N child views are arranged in a second orientation of a first layout container and indicates a first threshold and / or a second threshold of the first layout container in a first orientation, wherein the second orientation is different from the first orientation, and the second threshold is less than the first threshold; the determining, by the electronic device, attribute values of the N child views based on a device parameter of the electronic device and the preset capability comprises: determining, by the electronic device, an initial value of a dimension of the first layout container in the first orientation based on the device parameter; if the initial value is greater than the first threshold, determining that the dimension of the first layout container in the first orientation is the first threshold; or if the initial value is less than the second threshold, determining that the dimension of the first layout container in the first orientation is the second threshold; and determining a dimension of a first child view in the first layout container in the first orientation based on the dimension of the first layout container in the first orientation, wherein the first child view is one of the N child views; and the displaying, by the electronic device, the N child views on the second interface based on the attribute values of the N child views comprises: displaying, by the electronic device, the first child view on the second interface based on the attribute values of the N child views.

12. The method according to claim 11, wherein the determining a dimension of a first child view in the first layout container in the first orientation based on the dimension of the first layout container in the first orientation comprises: determining that the dimension of the first child view in the first orientation is the same as the dimension of the first layout container in the first orientation; or determining that the dimension of the first child view in the first orientation is the dimension of the first layout container in the first orientation minus an inner margin of the first layout container in the first orientation.

13. The method according to any one of claims 1 to 12, wherein the N child views each are any one of a text view, an edit view, a button view, and an image button view.

14. An electronic device, comprising a processor, a memory, and a touchscreen, wherein the memory, the touchscreen, and the processor are coupled, the memory is configured to store computer program code, the computer program code comprises computer instructions, and when the processor runs the computer instructions in the memory, the electronic device is enabled to perform the method according to any one of claims 1 to 12.

15. A computer-readable storage medium, comprising computer instructions, wherein when the computer instructions are run on an electronic device, the electronic device is enabled to perform the method according to any one of claims 1 to 12.

16. A computer program product, comprising computer instructions, wherein when the computer instructions are run on a computer, the computer is enabled to perform the method according to any one of claims 1 to 12.