Android split screen multi window practice code

Android n has launched multi window support. The project requires adaptation to multi window mode. Record it.

1. Life cycle: for apps that do not adapt to multiple windows at all, when the multi window mode is enabled or the window is dragged, the activity will be destroyed and reloaded. Solution: add the following line of attributes to the activity in the manifest file

2. When the multi window mode is enabled, there may be a need to change the original UI, which can be modified in the code:

Onmultiwindowmodechanged is available in both activity and fragment. This method will be called when the multi window mode changes. Note, however, that this method will not be called when entering a new page when it is already in multi window mode. Then what shall I do? The following method can be used to determine whether the current status is multi window. The minimum compatible SDK version is 24:

You can use this method of activity to judge. Hide or show some layouts when there are multiple windows.

3. If you want to dynamically change the layout during dragging multiple windows, you can configure the corresponding activity in the manifest file, for example:

Then set the layout of linear layout in the layout file of activity_ Gravity and weight:

It will change automatically in the process of dragging. This is an official demo of Android.

4. In the process of dragging multiple windows, it can also be set dynamically in the code. The onconfigurationchanged method will be called. There are a lot of information in the configuration newconfig parameter, including the width and height information of the current application.

Final recommendation: Android official documents

The above is the practice code of Android split screen and multi window introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>