Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of Android folding screen adaptation?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this article, the editor introduces in detail "what is the concept of Android folding screen adaptation". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the concept of Android folding screen adaptation" can help you solve your doubts.

Folding screen adaptation

The reason why the folding screen needs to be adapted is that the screen size of our application may have changed while it is running, which will cause some problems for existing projects.

So the essence of folding screen adaptation is that when the application runs, the size, density or proportion of the screen changes, and the application can continue to display and run normally on the changed screen.

In fact, this situation does not happen only after the emergence of the folding screen, and the same will happen in the vertical and horizontal switching of applications, but many applications are forced to be vertical, so there is no need to deal with this adaptation.

Allow application dimensions to be changed

To adapt to the folding screen, the first step is to enable the application to support dynamic resizing. We need to declare under Application or corresponding Activity in menifest:

Android:resizeableActivity= "true"

On the contrary, if you don't plan to adapt for the time being, set this parameter to false.

It is important to note that this parameter defaults to true in Android 7.0or later, and defaults to false below.

Here are two concepts related to this parameter.

Split screen mode

The reason why resizeableActivity has been changed to true by default since Android 7. 0 is that a new feature called split screen mode has been added in 7. 0.

.jpg

If resizeableActivity is set to false, it means that the application does not support split-screen mode, which determines whether the application has a split-screen setting.

.jpg

Compatibility mode

When resizeableActivity takes false, the effect of expanding the folding screen may be as follows:

.jpg

This effect is similar to using incompatible iPhone applications on iPad, which is surrounded by black-filled mode called compatibility mode.

The display of compatible mode is related to the maximum supported ratio maxAspectRatio. Black edges are used only when the screen ratio exceeds maxAspectRatio. It is officially recommended that maxAspectRatio be set to 2.4 (12: 5). The method to modify maxAspectRatio is as follows:

Android 8.0 or above

Configure android:maxAspectRatio in the tag:

Android version less than 8.0

Add a meta-data named android.max_aspect to the tag:

If resizeableActivity is set to true, there is no need to set maxAspectRatio, and the setting will not take effect.

Monitor size change

By default, when the screen changes, the system destroys and recreates the entire Activity. But we hope that after the screen changes, the program can continue to run in the state before the switch, and there is no need to restart the page.

We can add configuration to Activity:

Android:configChanges= "screenSize | smallestScreenSize | screenLayout"

After this configuration, the Activity will not be restarted when the screen changes. Instead, the onConfigurationChanged method will be called, in which we can get the current screen information:

@ Overridepublic void onConfigurationChanged (Configuration newConfig) {super.onConfigurationChanged (newConfig); Log.i ("config", "newConfig.screenHeightDp:" + newConfig.screenHeightDp + ", newConfig.screenWidthDp" + newConfig.screenWidthDp);}

After this change, you need to pay attention to the test to see if the layout of the page is out of order, and if the layout is unreasonable, you need to modify the layout to adapt to different resolutions.

We can also update the layout according to the screen information, such as switching LinearLayout to GridLayout on the big screen to make full use of the display space on the big screen, which is a further optimization:

.jpg

Android Q

Some features that support folding screens have been added to the upcoming Android Q.

Multi-resume

For split-screen mode, in the past, split-screen only supported two applications to display at the same time, but the large screen brought more possibilities, and now allows more than two applications to display at the same time.

In previous versions of Android Q, in applications running in split-screen mode, only the Activity that got the focus was in the onResume state, and the other visible Activity was in the onPause state.

On Android Q, all the top-level visible Activity are in onResume state, which ensures that the visible Activity in split-screen mode can work properly. But there is still only one Activity that can get focus, and we call this Activity TopResumedActivity.

A lifecycle callback method onTopResumedActivityChanged () has been added to the Activity of Android Q, which is called when the Activity gains or loses focus. It can be used to determine whether the current Activity has focus:

Protected void onTopResumedActivityChanged (boolean topResumed) {if (topResumed) {/ / get focus} else {/ / lose focus}}

This method is used when we use exclusive resources. What is the monopoly of resources? Microphones and cameras are such resources that can only be used by one Activity at a time.

For example, cameras are used in multiple Activity in split-screen mode, but only the Activity that gets the focus has access. In this case, it is necessary to use onTopResumedActivityChanged () to determine whether the current Activity has the focus. You can not release the camera when you lose focus, but you need to deal with the disconnection and reconnection of the camera.

.jpg

MinAspectRatio

Before Android Q, you can only configure the maximum support ratio maxAspectRatio. Now Android Q can configure the minimum support ratio minAspectRatio, using the same method as maxAspectRatio:

The maximum and minimum support ratio is only useful when resizeableActivity uses false.

Debug

Of course, the best debugging tool is to use the real machine, but at present only a small number of people have this condition, here are two debugging schemes other than the real machine.

Android Studio

With the addition of a virtual machine for folding screen devices in Android Studio 3.5, we can create one to debug:

.jpg

By clicking the button on the simulator, we can switch the collapsed and expanded state of the virtual machine:

.jpg

Command Lin

We can use the command to modify the resolution of the phone to achieve the effect of switching between simulated folding screens. Take the resolution of Mate X as an example, we first use the command line:

Adb shell wm size 1148x2480

The resolution of the phone will be simulated as 1148x2480, which is the resolution of Mate X when it is folded, then enter:

Adb shell wm size 2200x2480

The resolution of the mobile phone is modified to the resolution 2200x2480 of the expanded Mate X, and the switching of the folding screen is simulated in this way.

You can change the resolution to 1148x2480 again to simulate the screen folding switch. Finally, when it is over, use the following command line to restore the phone's own resolution:

Adb shell wm size reset

After reading this, the article "what is the concept of Android folding screen adaptation" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report