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

相关内容

热门资讯

推荐几款新版!哈糖大菠萝可以开... 推荐几款新版!哈糖大菠萝可以开挂吗,约局吧是否有挂,必胜教程(有挂神器);支持多人共享记分板与复盘,...
玩家必看科普!uupoker有... 您好,wepoker模拟器哪个这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...
重要通知!pokemmo修改器... 此外,数据分析德州(pokemmo修改器手机版)辅助神器app还具备辅助透视行为开挂功能,通过对客户...
推荐一款!aapoker真的假... 推荐一款!aapoker真的假的,aapoker透视脚本,线上教程(有挂软件);最新版2024是一款...
今日百科!wepoker私人局... 今日百科!wepoker私人局开挂视频,wepoker辅助器如何使用,黑科技教程(有挂技巧)准备好在...
我来教教你!wpk作弊,hhp... 这是一款非常优秀的hhpoker作弊码怎么用 ia辅助检测软件,能够让你了解到hhpoker作弊码怎...
科技新动态!黑侠破解wepok... 1、科技新动态!黑侠破解wepoker,aapoker透视脚本入口,教你教程(有挂辅助);详细教程。...
专业讨论!wepoker挂,h... 专业讨论!wepoker挂,hhpoker是正规的吗,解说技巧(有挂辅助)准备好在hhpoker是正...
技术分享!hhpoker有没有... 技术分享!hhpoker有没有作弊辅助,wepoker免费脚本咨询,规律教程(有挂攻略);大神普及一...
指导大家!wepoker透视辅... 指导大家!wepoker透视辅助下载,wepoker游戏的安装教程,规律教程(有挂技巧);最新版20...