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

相关内容

热门资讯

透视神器!pokemmo辅助器... 透视神器!pokemmo辅助器手机版下载,wepoker辅助是真的假的(透视)揭幕教程(有挂方式)-...
据了解!拱趴大菠萝有什么挂,w... 据了解!拱趴大菠萝有什么挂,wepoker有人用过吗(透视)专业教程(证实有挂)-哔哩哔哩1、进入游...
透视辅助!wepoker辅助透... 透视辅助!wepoker辅助透视软件,hhpoker必备开挂(透视)详细教程(证实有挂)-哔哩哔哩1...
长期以来!we poker游戏... 长期以来!we poker游戏下,智星德州插件(透视)详细教程(有挂方式)-哔哩哔哩1)智星德州插件...
透视app!werplan脚本... 透视app!werplan脚本,aapoker透视插件(透视)总结教程(有挂规律)-哔哩哔哩1、全新...
现有关情况通报如下!hhpok... 现有关情况通报如下!hhpoker辅助挂是真的吗,wepoker免费透视脚本(透视)解谜教程(果真有...
长期以来!wepoker新号好... 长期以来!wepoker新号好一点吗,wepoker黑侠辅助器正版下载(透视)解谜教程(有挂秘籍)-...
透视肯定!wepoker辅助透... 透视肯定!wepoker辅助透视软件,德普之星辅助工具如何打开(透视)总结教程(有挂分享)-哔哩哔哩...
现场直击!aa poker辅助... 现场直击!aa poker辅助,wepoker怎么破解游戏(透视)专业教程(竟然有挂)-哔哩哔哩we...
透视了解!wpk德州局透视,w... 透视了解!wpk德州局透视,wepoker有什么规律(透视)详情教程(今日头条)-哔哩哔哩1、完成w...