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

相关内容

热门资讯

科技新动态!wepoker新号... 1、科技新动态!wepoker新号好一点吗,wepokerplus作弊,微扑克教程(有挂透明)2、进...
推荐一款!aapoker透视怎... 推荐一款!aapoker透视怎么用,约局吧怎么看有没有挂,透明挂教程(有挂技巧)1、很好的工具软件,...
新手必备!wepoker透视版... 您好,wepoker透视版下载这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...
玩家必看秘籍!pokemmo辅... 玩家必看秘籍!pokemmo辅助脚本,pokemmo脚本辅助器下载,必胜教程(有挂透明)科技教程也叫...
新手必备!约局吧app有挂吗,... 新手必备!约局吧app有挂吗,aa poker辅助,可靠技巧(有挂教程)是一款可以让一直输的玩家,快...
推荐攻略!aapoker脚本怎... 推荐攻略!aapoker脚本怎么用,德普辅助软件,详细教程(有挂方法)这是由厦门游乐互动科技有限公司...
分享个大家!we-poker靠... 此外,数据分析德州(we-poker靠谱吗)辅助神器app还具备辅助透视行为开挂功能,通过对客户we...
玩家必看秘籍!pokemmo辅... 玩家必看秘籍!pokemmo辅助器脚本下载,aa poker透视软件,揭秘教程(有挂技巧);玩家必备...
分享认知!wepoker手机插... 分享认知!wepoker手机插件,poker红龙辅助,必胜教程(有挂技巧)准备好在wepoker手机...
玩家必备科普!hh poker... 玩家必备科普!hh poker辅助有用吗,hhpoker开挂教程,透明挂教程(有挂技巧);最新版20...