Android11上的多窗口模式+
创始人
2024-08-20 11:30:05
0

Android 11引入了新的多窗口模式增强功能,允许用户将应用程序分割成多个窗口同时运行。这个新的功能需要在代码中进行一些调整,在此提供一个简单的代码示例以启发实现。

为了支持多窗口,需要在应用程序的活动中添加以下代码片段:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) { 
    getWindow().setDecorFitsSystemWindows(false); 
    final WindowMetrics windowMetrics = getWindowManager().getCurrentWindowMetrics(); 
    final Insets insets = windowMetrics.getWindowInsets().getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()); 
    final int insetsWidth = insets.left + insets.right; 
    final int insetsHeight = insets.top + insets.bottom; 

    final Rect bounds = windowMetrics.getBounds(); 
    bounds.inset(insets); 
    final int width = bounds.width(); 
    final int height = bounds.height(); 

    final Rational aspectRatio = new Rational(width, height); 
    final Pair pair = new Pair<>( 
        WindowLayoutInfo.Builder.from(getWindow(), null).setBounds(bounds).setForegroundInsets(insets).setSystemGestureInsets(insets).setTrustedOverlay(true).build(), 
        ActivityOptions.makeBasic().setLaunchWindowingMode(SCREEN_SPLIT_SECONDARY).setTaskAlwaysOnTop(true).setTaskWindowingMode(SPLIT_SCREEN_CREATED).setActivityLaunchAnimation(NO_ANIMATION) 
    ); 

    getWindow().setWindowLayoutInfo(pair.first); 
    startActivity(getApplicationInfo().packageName, MainActivity.class, null, pair.second.toBundle()); 
    finish(); 
}

这个代码片段做了很多事情,包括:

  • 获取窗口度量,并计算中心窗口的边界和偏移量。
  • 创建一个rationale宽高比,以便系统可以更好地管理多个窗口之间的相同宽高比。
  • 构建一个窗口布局信息对象,将其与活动选项绑定,并启

相关内容

热门资讯

解密透视!德普软件,微乐小程序... 解密透视!德普软件,微乐小程序辅助开发,办法教程(有挂分享)-哔哩哔哩1、在德普软件插件功能辅助器技...
解谜透视!hh poker透视... 解谜透视!hh poker透视器下载,微乐自建房插件详细教程,模块教程(有挂攻略)-哔哩哔哩1、很好...
必备透视!拱趴大菠萝机器人,微... 必备透视!拱趴大菠萝机器人,微乐广西麻辣辅助,手筋教程(有挂存在)-哔哩哔哩1、操作简单,无需拱趴大...
了解透视!wepoker透视a... 了解透视!wepoker透视app下载,微乐山西小程序破解器,秘籍教程(有挂存在)-哔哩哔哩1、实时...
总结透视!wepoker辅助分... 总结透视!wepoker辅助分析器,微乐广西小程序插件,诀窍教程(有挂工具)-哔哩哔哩wepoker...
有挂透视!智星德州辅助译码插件... 有挂透视!智星德州辅助译码插件靠谱吗,陕西微乐小程序脚本,绝活教程(确实有挂)-哔哩哔哩1、智星德州...
解迷透视!hhpoker的辅助... 解迷透视!hhpoker的辅助是真的吗,微乐辅助脚本,操作教程(有挂解惑)-哔哩哔哩1、上手简单,内...
辅助透视!约局吧透视挂下载,微... 辅助透视!约局吧透视挂下载,微乐家乡小程序脚本,模板教程(存在有挂)-哔哩哔哩约局吧透视挂下载脚本下...
必备透视!aapoker插件,... 必备透视!aapoker插件,微乐小程序辅助器免费安卓,课程教程(有人有挂)-哔哩哔哩一、aapok...
普及透视!聚星ai辅助工具下载... 您好,聚星ai辅助工具下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...