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宽高比,以便系统可以更好地管理多个窗口之间的相同宽高比。
  • 构建一个窗口布局信息对象,将其与活动选项绑定,并启

相关内容

热门资讯

昨日!newpoker脚本,微... 昨日!newpoker脚本,微信小程序微乐辅助器教程图片,关于脚本(有挂规律)-哔哩哔哩1、玩家可以...
脚本了解!aapoker免费透... 脚本了解!aapoker免费透视脚本,aapoker辅助工具安全吗(透视)都是真的是有神器(哔哩哔哩...
透视讲解!hhpoker真的假... 透视讲解!hhpoker真的假的,微信微乐小程序有窍门吗,总结透视(发现有挂)-哔哩哔哩1、任何hh...
透视揭露!hhpoker德州挂... 透视揭露!hhpoker德州挂真的有吗,hhpoker辅助软件下载(透视)其实是真的器(哔哩哔哩)脚...
透视挂!wepoker怎么发冤... 透视挂!wepoker怎么发冤家牌,微乐兰州麻将小程序辅助,推荐脚本(有挂技巧)-哔哩哔哩1、wep...
脚本分享!hhpoker免费透... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
今天下午!wepoker手机版... 今天下午!wepoker手机版透视脚本,手机微乐小程序破解器如何使用,关于脚本(有挂分析)-哔哩哔哩...
脚本详细!德普之星透视辅助插件... 脚本详细!德普之星透视辅助插件,德普辅助器怎么用(透视)切实是真的工具(哔哩哔哩)1、免费脚本咨询教...
最终!竞技联盟透视插件,微乐辅... 最终!竞技联盟透视插件,微乐辅助脚本,开挂透视(真是有挂)-哔哩哔哩1、下载好竞技联盟透视插件脚本下...
脚本揭露!wpk透视辅助下载,... 脚本揭露!wpk透视辅助下载,wpk作必弊(透视)确实存在有插件(哔哩哔哩)1、任何透视是真的假的的...