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

相关内容

热门资讯

WPK私人局!智星菠萝德州软件... WPK私人局!智星菠萝德州软件透视挂ai,哈糖大菠萝破解器,本来真的有ai透视挂大纲1、哈糖大菠萝破...
WPK靠谱!微扑克攻略辅助ai... WPK靠谱!微扑克攻略辅助ai,AApoker底牌,原来真的是有ai辅助方案1、打开软件启动之后找到...
WPK模拟器!wpk脚本辅助器... WPK模拟器!wpk脚本辅助器ai,智星德州可以透视吗,真是存在有ai辅助器策略1、游戏颠覆性的策略...
WPK真假!菠萝智星德州攻略辅... WPK真假!菠萝智星德州攻略辅助ai,aapoker俱乐部靠谱吗,好像有ai辅助模块1、aapoke...
WPK透视版!德州扑克教程开挂... WPK透视版!德州扑克教程开挂ai,wpk可以作弊吗,竟然存在有ai开挂攻略1、许多玩家不知道wpk...
WPK下载!WePoKer软件... WPK下载!WePoKer软件辅助ai,wpk真吗,切实是有ai辅助妙计1、上手简单,内置详细流程视...
WPK德州局!德州扑克神器辅助... WPK德州局!德州扑克神器辅助ai,拱趴大菠萝作弊方法,确实有ai辅助课程拱趴大菠萝作弊方法是不是有...
WPK软件!智星菠萝德州技巧透... WPK软件!智星菠萝德州技巧透视ai,德普之星透视辅助插件,都是是有ai透视窍门1、德普之星透视辅助...
WPK安装!德州扑克技巧透视a... WPK安装!德州扑克技巧透视ai,约局吧怎么看有没有挂,一直真的是有ai透视技法约局吧怎么看有没有挂...
WPK控制牌!微扑克工具开挂a... WPK控制牌!微扑克工具开挂ai,哈糖大菠萝挂法,果然真的是有ai开挂大纲所有人都在同一条线上,像星...