laitimes

The official guide for vivo X Fold folding screen adaptation has been released

IT home April 30 news, a few days ago, vivo's first folding screen mobile phone officially announced, in order to allow developers to better adapt to the new model, vivo team launched a new adaptation guide.

The official guide for vivo X Fold folding screen adaptation has been released

Vivo folding screen has an expanded state and a folded state, and the resolution of the screen is different in these two states. Therefore, when the folding screen state is switched, the resolution should also be dynamically switched.

If the app or activity does not support automatic adaptation of different resolution screens, there will be some display anomalies, such as the left and right or lower half of the screen shown in the following figure:

Expanded ▼

The official guide for vivo X Fold folding screen adaptation has been released

Folded ▼

The official guide for vivo X Fold folding screen adaptation has been released

Adaptation recommendations

#01

Make your app resizable

In order to enhance the user experience, when the folding screen is dynamically switched between the expanded state and the folded state, the application interface does not allow the existence of left and right black edges or the black edge of the lower half screen (that is, the application enters compatibility mode), so the application needs to support the adjustment of the page size at different resolutions.

This feature is controlled by the android:resizeableActivity property, which can be set for apps or activities in the app's AndroidManifest .xml.

Note:

1. When the targetSdkVersion of the application >=24, the android system defaults to android:resizeableActivity="true", which does not require an application declaration to support the application size adjustment. When targetSdkVersion is applied

2. Application android:resizeableActivity="true" takes effect for all activities of the app, so when the application only needs to declare individual activities, it can be set for only a single activity.

System suggestion: set android:resizeableActivity="true" for application to avoid black-edged problems in some pages of the application after the state of the folding screen changes.

Additional adaptations can be found in the Android Developer Adaptation Guide (e.g. the Save UI State and Support Configuration Changes section mentioned in the link):

https://developer.android.com/guide/topics/ui/foldables?hl=zh-cn

3. After setting android:resizeableActivity="true", the application can enter split screen mode, if you do not want to enter split screen mode (there will be some adaptation problems after entering split screen mode) and are not treated as compatibility mode, you can add the following code in the activity:

#02

Different resolution layouts are adapted

Folding screen involves different resolution sizes and DPI, the application interface in addition to to ensuring that the resolution switch when no black edge problem, but also need to ensure that the application interface in different resolutions display page without obvious stretching, misalignment and overlap and other issues, so it is necessary to optimize the layout and provide the corresponding bitmap for adaptation.

For detailed adaptation methods, please refer to the following links:

https://developer.android.com/training/multiscreen/screensizes?hl=zh-cn

#03

Adapt to the large-screen experience

When adapted to the large screen, part of the display page is only enlarged, and the space of the large screen is not used to display more content.

Therefore, developers need to effectively use the large screen space to adjust the layout display and display more content.

The official guide for vivo X Fold folding screen adaptation has been released

To solve such display problems, developers can declare "screenSize" changes in AndroidManifest .xml android:configChanges, and then dynamically adjust the layout in onConfigurationChanged.

For detailed adaptation methods, please refer to the following links:

https://developer.android.com/guide/topics/resources/runtime-changes?hl=zh-cn

#04

Determine the folding screen method

Runtime judgment:

android.util.FtDeviceInfo

public static String getDeviceType

Three types returned: phone, tablet, and foldable

Developers can obtain the device type by reflecting, and the return value foldable indicates the folding screen device.

Reflection code example:

private static boolean isVivoFoldableDevice(){ try { Classc= Class.forName("android.util.FtDeviceInfo"); Method m = c.getMethod("getDeviceType"); Object dType = m.invoke(c); Log.d("fold","getDeviceType="+dType); return "foldable".equals(dType); } catch (Exception e) { e.printStackTrace(); } return false;}

#05

Model configuration

If the application has been adapted for other manufacturers of folding screen equipment, the new folding screen device can take effect according to the model name configuration, and the vivo folding screen model model V2178A can be directly configured.

Debugging and validation

#01

Phone debugging

DPI setting: adb shell wm density 480

Expansion: adb shell wm size 1916x2160

Folded: adb shell wm size 1080x2520

Note:

1. The folding screen expansion state and the folded state DPI are the same as 480, and only need to be set once

2. When switching between expanded and collapsed states, you can simulate the switching by setting different resolutions

3. Ways to view the phone's current DPI and size: adb shell wm density and adb shell wm size

4. After the DPI and resolution settings, the settings of the restarted phone will not change, if you need to call back the phone default, you can restore it through the adb shell wm size reset and the adb shell wm density reset

5. Due to the debugging efficiency of the Android emulator, it is recommended to use the mobile phone to simulate debugging and verification; if you need to restore the physical size of the real machine 100%, you can consider the emulator

#02

Emulator debugging

In addition to debugging by dynamically switching resolutions on the phone, debugging and verification can also be carried out through the simulator. The Android Studio Emulator Phone classification supports 8-inch and 7.3-inch folding screen debugging, but cannot be cloned (that is, the physical size and resolution of the emulator cannot be modified).

Emulator System image Only supports the installation and operation of 32-bit apps if it is an x86 system; if it is a pure 64-bit app, the emulator needs to select arm64-v8a, otherwise the app cannot be installed and run.

The official guide for vivo X Fold folding screen adaptation has been released

Note:

1. The Android Studio Foldable emulator cannot modify the physical size, resolution and DPI, so when adapted, it is not possible to fully emulate the vivo folding screen phone, and when the App or activity resizeableActivity = true, in order to verify whether the screen cut has a black edge, the effect can be viewed in the Android native emulator.

The official guide for vivo X Fold folding screen adaptation has been released

2. The 64-bit emulator requires PC host support, and some PCs cannot start the 64-bit emulator properly.

#03

Collapse the flattening simulator

The Android Folding Screen Emulator cannot modify physical dimensions, resolution, and DPI. If the application needs a screen that simulates the unfolding state of the folding screen for debugging when adapting to the 2.2 different resolution layout, you can debug and verify by cloning the Nexus 10 classified by tablet, and then modify the physical size, resolution and DPI corresponding to the vivo folding screen mobile phone.

The official guide for vivo X Fold folding screen adaptation has been released

Note:

1. When the app UI compatibility adaptation has a strong correlation with the physical size, be sure to modify the Screen size to 8.03 and the resolution is the flat resolution

2. You need to confirm that the 64-bit emulator can run and require PC host support

3. If the mobile phone simulates DPI and resolution debugging without problems, it cannot run in the simulator, you can send a package to the vivo interface person and run the spot check on the vivo folding screen real machine

4. The emulator cannot modify the DPI, you need to start the emulator and set it through the adb shell command

Open the terminal at this time, you can see that the emulator device is mounted and connected, and you can perform adb operations.

λ adb devicesList of devices attachedemulator-5554 device

The emulator cannot directly modify the DPI and needs to be set separately after starting the emulator.

adb shell wm density 480

Read on