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

相关内容

热门资讯

交流学习经验!约局吧app有挂... 交流学习经验!约局吧app有挂吗,wepoker永久免费脚本,可靠技巧(有挂辅助);人气非常高,ai...
透视新版!wepoker透视脚... 透视新版!wepoker透视脚本(透视)原来是真的有挂(详细辅助微扑克教程)1、点击下载安装,wep...
指导大家!aapoker发牌逻... 指导大家!aapoker发牌逻辑,哈糖大菠萝软件下载,细节方法(有挂技巧)准备好在哈糖大菠萝软件下载...
透视辅助!德扑圈透视(透视)一... 透视辅助!德扑圈透视(透视)一直真的有挂(详细辅助扑克教程)1、完成的残局,帮助玩家取得所有比赛的胜...
每日必备!德州局hhpoker... 这是一款非常优秀的约局吧游戏挂 ia辅助检测软件,能够让你了解到约局吧游戏挂中牌率当中全部隐藏参数,...
透视了解!wepoker有辅助... 透视了解!wepoker有辅助插件吗(透视)其实有挂(详细辅助详细教程)1、系统规律教程、辅助透视等...
今日百科!wepoker黑侠辅... 《今日百科!wepoker黑侠辅助器正版下载,哈糖大菠萝免费辅助器,可靠教程(有挂技巧)》 wepo...
透视插件!wepoker透视版... 透视插件!wepoker透视版下载(透视)竟然真的有挂(详细辅助力荐教程)1、首先打开wepoker...
盘点一款!wepoker怎么挂... 盘点一款!wepoker怎么挂底牌,德州hhpoker脚本,必赢教程(有挂神器);支持多人共享记分板...
透视美元局!wepoker可以... 透视美元局!wepoker可以透视码(透视)其实存在有挂(详细辅助技巧教程);1、机器人多个强度级别...