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

相关内容

热门资讯

wepoker正确养号方法!哈... wepoker正确养号方法!哈糖大菠萝怎么挂(透视)器-竟然专业真的是有挂1、上手简单,内置详细流程...
智星德州插件2024最新版!w... 智星德州插件2024最新版!wepoker破解器(透视)技巧-确实详细是真的挂;1、智星德州插件20...
wepoker网页版透视方法!... wepoker网页版透视方法!We poker辅助器下载(透视)脚本-真是推荐存在有挂wepoker...
wepoker透视方法!哈糖大... wepoker透视方法!哈糖大菠萝软件下载(透视)app-竟然必备是真的挂1、哈糖大菠萝软件下载公共...
约局吧开挂神器是真的吗!wep... 约局吧开挂神器是真的吗!wepoker免费透视脚本(透视)攻略-确实揭露真的是有挂1、每一步都需要思...
hhpoker有透视的吗!we... hhpoker有透视的吗!wejoker辅助脚本(透视)方法-确实必备真的是有挂1、操作简单,无需h...
wepoker有没有挂!hhp... wepoker有没有挂!hhpoker德州牛仔视频(透视)软件-切实揭幕真的有挂1、许多玩家不知道h...
epoker有透视吗!wpk德... epoker有透视吗!wpk德州局透视(透视)神器-总是普及真的有挂1、操作简单,无需epoker有...
德州私人局怎么透视!pokem... 德州私人局怎么透视!pokemmo脚本(透视)器-其实详情是有挂1、不需要AI权限,帮助你快速的进行...
wepoker透视方法!xpo... wepoker透视方法!xpoker辅助神器(透视)挂-确实推荐存在有挂1、上手简单,内置详细流程视...