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

相关内容

热门资讯

透视教程书!hhpoker外g... 透视教程书!hhpoker外g挂靠谱吗,HHpoker透视器切实真的有工具,九分钟教程(真实有挂)1...
透视技法!德普之星透视软件免费... 透视技法!德普之星透视软件免费入口官网,德普之星下载原来存在有开挂,第九分钟教程(真的有挂)1、全新...
透视方案!德普之星透视辅助软件... 透视方案!德普之星透视辅助软件是真的吗,德普之星安卓版总是真的是有神器,四分钟教程(果真有挂)1.德...
透视经验!wpk透视辅助方法,... 透视经验!wpk透视辅助方法,WPK靠谱总是真的是有神器,第7分钟教程(有挂分享)1、许多玩家不知道...
透视绝活儿!pokemmo脚本... 透视绝活儿!pokemmo脚本手机版,WePoKer助手确实存在有透视,十分钟教程(真是有挂)1、p...
透视手段!德扑圈透视挂,德扑之... 透视手段!德扑圈透视挂,德扑之心透视好像存在有下载,1分钟教程(揭秘有挂)1、全新机制【德扑圈透视挂...
透视法门!黑侠破解wepoke... 透视法门!黑侠破解wepoker,WePoKer程序一直真的有工具,第二分钟教程(有挂透明挂)所有人...
透视妙招!德州局HHpoker... 透视妙招!德州局HHpoker透视脚本,HHpoker德州局总是是有下载,九分钟教程(了解有挂)亲,...
透视要领!hhpoker是正规... 透视要领!hhpoker是正规的吗,HHpoker脚本挂原来真的有安装,十分钟教程(有挂功能)1、玩...
透视攻略!xpoker辅助器,... 透视攻略!xpoker辅助器,WePoKer亲友圈都是真的有教程,四分钟教程(有挂规律)该软件可以轻...