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

相关内容

热门资讯

重大通报!pokermaste... 重大通报!pokermaster辅助器,wepoker模拟器哪个好用,解密教程(有挂攻略);支持多人...
透视规律!wpk模拟器多开(透... 透视规律!wpk模拟器多开(透视)一贯是有挂(详细辅助透明挂教程)1、首先打开最新版本,在首页我们可...
透视ai代打!hhpoker辅... 透视ai代打!hhpoker辅助软件下载(透视)总是是有挂(详细辅助解说技巧)1、该软件可以轻松地帮...
记者揭秘!poker辅助器免费... 1、记者揭秘!poker辅助器免费安装,wepoker透视苹果系统,技巧教程(有挂技巧)。2、pok...
透视辅助!约局吧是否有挂(透视... 透视辅助!约局吧是否有挂(透视)真是存在有挂(详细辅助揭秘教程);1、机器人多个强度级别选择2、发牌...
记者揭秘!hhpoker哪个俱... 1、记者揭秘!hhpoker哪个俱乐部靠谱,德州辅助工具到底怎么样,扑克教程(有挂攻略);详细教程。...
免费测试版!wepoker辅助... 1、免费测试版!wepoker辅助分析器,拱趴大菠萝自动计算机器人,分享教程(有挂方法)2、进入游戏...
透视新版!wepoker可以透... 透视新版!wepoker可以透视码(透视)好像有挂(详细辅助攻略教程);1、完成的残局,帮助玩家取得...
科普常识!aapoker发牌逻... 科普常识!aapoker发牌逻辑,拱趴大菠萝万能挂图解,透明挂教程(有挂技巧);人气非常高,ai更新...
透视攻略!wepoker怎么拿... 透视攻略!wepoker怎么拿到好牌(透视)真是有挂(详细辅助揭秘教程)一、AI软件牌型概率发牌机制...