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、操作简单,无需we...
无独有偶!poker worl... 无独有偶!poker world辅助器(透视)竟然有辅助app(有挂实锤)-哔哩哔哩1、poker ...
透视透视!htx矩阵wepok... 透视透视!htx矩阵wepoker辅助(透视)果然存在有辅助平台(有挂细节)-哔哩哔哩1、进入游戏-...
截至发稿!wejoker辅助脚... 截至发稿!wejoker辅助脚本(透视)确实存在有辅助app(真的有挂)-哔哩哔哩1)wejoker...
透视中牌率!wepoker透视... 透视中牌率!wepoker透视脚本免费使用视频(透视)确实存在有辅助工具(有挂功能)-哔哩哔哩1、很...
透视免费!wepoker安装教... 您好,wepoker安装教程这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...
透视玄学!红龙poker辅助器... 透视玄学!红龙poker辅助器免费观看(透视)其实真的是有辅助软件(有挂分享)-哔哩哔哩小薇(辅助器...
此事迅速冲上热搜!wejoke... 此事迅速冲上热搜!wejoker辅助器怎么卖(透视)一贯有辅助安装(有挂方针)-哔哩哔哩1、全新机制...
透视挂!wpk作必弊最怕三个东... 透视挂!wpk作必弊最怕三个东西(透视)其实真的有辅助安装(有挂技巧)-哔哩哔哩1、操作简单,无需w...
据报道!wepoker作必弊方... 据报道!wepoker作必弊方法(透视)一直是有辅助安装(有挂方法)-哔哩哔哩1、下载好wepoke...