As more and more large and folding screen devices appear, many applications do not have UI adaptations for devices of different sizes, when the application chooses to display in a specific aspect ratio (although Google does not recommend this, the official hope that developers can adapt the layout of different screen sizes ~), when the application’s aspect ratio and its container ratio is not compatible, it will be opened in Letterbox mode.
Letterbox mode displays the interface at a specified scale, and the surrounding blank area can be filled with wallpaper or colors. The appearance of the Letterbox can be influenced by the following factors.
config_letterboxActivityCornersRadius: the size of the rounded corners of the interface
config_letterboxBackgroundType: background fill type, respectively.
LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND: Color is affected by
LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING: color is affected by
LETTERBOX_BACKGROUND_SOLID_COLOR: color is affected by
LETTERBOX_BACKGROUND_WALLPAPER: Show wallpaper, this option is similar to
FLAG_SHOW_WALLPAPERand will cause the wallpaper window to be displayed
config_letterboxBackgroundWallpaperBlurRadius: the wallpaper blurring level
config_letterboxBackgroundWallpaperDarkScrimAlpha: how dark the wallpaper is
2. when to trigger
Letterbox is generally triggered by.
android:resizeableActivity=falseand when the declared aspect ratio of the application is not compatible with the container (e.g. the screen width exceeds
setIgnoreOrientationRequest(true)After the system is set to ignore the screen orientation, an interface with a forced vertical screen is opened in landscape mode.
3. implementation scheme
The implementation of Letterbox display is not complicated, Android 12 added
ActivityRecord to control the layout and display of
Letterbox, let’s see the SurfaceFlinger state when it is in Letterbox mode.
As you can see, compared to the normal case, in addition to the size and position of the interface itself being scaled to a specified proportion, there are two more Layers around, hanging under the ActiviRecord node.
Here is a brief analysis of the code.
This article only briefly analyzed the trigger conditions and the general logic of displaying Letterbox mode, there are many details not covered, such as the detailed trigger logic judgment can check the