In current practice, you set designWidth to the screen width for your quick app. In this case, if the same content is displayed on a wider device, the content is enlarged. As a result, your quick app cannot be displayed properly on a large screen, a phone in landscape orientation, or an unfolded foldable screen.

This topic provides guidance for you to develop or reconstruct a quick app using responsive layout. Responsive layout enables your quick app to be displayed properly on devices with various sizes, such as large screens, mobile phones in landscape orientation, and unfolded foldable screens.

Developing a New Quick App

Configuring the manifest File

1. Set minPlatformVersion to 1066 or a later version.

  1. "minPlatformVersion": 1066,

2. Change the value of designWidth in the config section in the manifest.json file to device-width.

  1. "config": {
  2.    "designWidth": "device-width"
  3. },

Planning the Layout of UI Elements

Plan the sizes and layout of UI elements based on common screen widths. Common screen widths are as follows:

Setting Dynamic Layout

To adapt your app to various screens, you are advised to pay attention to the following:

If the simple dynamic layout cannot achieve the expected effect, you can use Media Query. For example, the following code can be used to control the number of columns to display in a list based on the screen width:

  1. /**
  2. * For a regular phone in portrait orientation (360 px wide), display three images in a line, with each image occupying 120 px.
  3. */
  4. @media screen and (min-width: 0) and (max-width: 239) {
  5.         .list {
  6.                   columns: 1;
  7.         }
  8. }
  9. @media screen and (min-width: 240) and (max-width: 359) {
  10.         .list {
  11.                   columns: 2;
  12.         }
  13. }
  14. @media screen and (min-width: 360) and (max-width: 479) {
  15.         .list {
  16.                   columns: 3;
  17.         }
  18. }
  19. @media screen and (min-width: 480) and (max-width: 599) {
  20.         .list {
  21.                   columns: 4;
  22.         }
  23. }
  24. @media screen and (min-width: 600) and (max-width: 719) {
  25.         .list {
  26.                   columns: 5;
  27.         }
  28. }
  29. @media screen and (min-width: 720) and (max-width: 839) {
  30.         .list {
  31.                   columns: 6;
  32.         }
  33. }
  34. @media screen and (min-width: 840) and (max-width: 959) {
  35.         .list {
  36.                   columns: 7;
  37.         }
  38. }
  39. @media screen and (min-width: 960) and (max-width: 1079) {
  40.         .list {
  41.                   columns: 8;
  42.         }
  43. }
  44. @media screen and (min-width: 1080) {
  45.         .list {
  46.                   columns: 9;
  47.         }
  48. }

After the settings, the display effect varies depending on the screen width, as shown in the following figures.    

Reconstructing a Quick App

Configuring the manifest File

Change the value of designWidth in the config section in the manifest.json file to device-width.

  1. "config": {
  2.    "designWidth": "device-width"
  3. },

Planning the Layout of UI Elements

Plan the sizes and layout of UI elements based on common screen widths. Common screen widths are as follows:

Adapting Sizes

After setting designWidth to device-width, adapt the sizes in the ux and css files of your project. The size conversion formula is as follows: New size = Old size x 36/75. The following figures show the mapping between the new and old sizes.

       

You can download the convert tool, and run the following command to convert the sizes:

  1. java -jar convert.jar -root D:\workspace\quickapp\project -formats "ux;css"
Caution:

Adapting a Card

Adaptation for a card is the same as that for a quick app except the change of designWidth. Change the value of designWidth as follows:
Open the ux file corresponding to the card and add designWidth="device-width" to the level-1 node in the template.

Adaptation Example

designWidth: 750 is used as an example. Before the adaptation, the display effects on a foldable screen after being folded and unfolded are shown in the following figures. It is obvious that the size of each element is enlarged when the screen is unfolded.

   

Modifying the manifest File

Change "designWidth" in the manifest file to "designWidth":"device-width".

Using the Tool to Convert Sizes

  1. d:\>java -jar convert.jar -root D:\workspace\fastapp\MultiLayout -formats "ux;css"


The following figure shows the files before and after the conversion.

Using Media Query

After the conversion, only two images are displayed in one line on the wide screen, leaving much empty space.

To resolve this issue, use Media Query to dynamically adjust the number of columns to display.

The following figure shows the display effect after the adjustment.

Download sample code: Before Adaptation   After Adaptation