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

相关内容

热门资讯

透视学习!aapoker透视方... 透视学习!aapoker透视方法,aapoker安装包怎么使用(透视)一直有脚本教程(哔哩哔哩)亲,...
透视步骤!hhpoker作必弊... 透视步骤!hhpoker作必弊码怎么用,wepoker辅助透视软件(透视)一直有挂(哔哩哔哩)1、用...
透视策略!hhpoker到底可... 透视策略!hhpoker到底可以作必弊码,hhpoker俱乐部是干嘛的(透视)本来是真的透视脚本(哔...
透视攻略!hhpoker万能辅... 透视攻略!hhpoker万能辅助器,wepoker黑侠破解(透视)确实是有挂(哔哩哔哩)1、这是跨平...
透视策略!德普之星有辅助软件吗... 透视策略!德普之星有辅助软件吗,wepoker透视有没有(透视)确实真的是有挂(哔哩哔哩)1、德普之...
透视烘培!wejoker辅助软... 透视烘培!wejoker辅助软件价格,wepoker私人局辅助挂(透视)好像是真的透视挂(哔哩哔哩)...
透视项目!wepoker看底牌... 透视项目!wepoker看底牌,哈糖大菠萝破解器(透视)一直存在有挂(哔哩哔哩)该软件可以轻松地帮助...
透视模块!hhpoker怎么开... 透视模块!hhpoker怎么开透视,hhpoker免费透视脚本(透视)果然存在有脚本app(哔哩哔哩...
透视绝活儿!大菠萝免费辅助器,... 透视绝活儿!大菠萝免费辅助器,wpk真吗(透视)竟然是有挂(哔哩哔哩)1、不需要AI权限,帮助你快速...
透视演示!德普之星透视辅助,德... 透视演示!德普之星透视辅助,德普之星辅助器怎么用(透视)一直存在有脚本教程(哔哩哔哩)1、任何德普之...