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辅助哪里买,w... 透视详细!wpk辅助哪里买,wpk俱乐部怎么作必弊(透视)其实真的是有脚本(哔哩哔哩)1、免费辅助多...
随着!wejoker辅助器怎么... 随着!wejoker辅助器怎么卖,万能透视辅助器免费版,总结脚本(有挂方法)-哔哩哔哩1、wejok...
脚本透视!德普之星有辅助软件吗... 脚本透视!德普之星有辅助软件吗,德普之星透视辅助软件(透视)竟然有挂(哔哩哔哩)1、不需要AI权限,...
迎来新发展!破解辅助插件wep... 迎来新发展!破解辅助插件wepoker,微乐家乡麻将辅助,了解透视(今日头条)-哔哩哔哩破解辅助插件...
脚本教你!aapoker公共底... 脚本教你!aapoker公共底牌,aapoker怎么选牌(透视)真是真的是有教程(哔哩哔哩)1、点击...
截至目前!wepoker能不能... 截至目前!wepoker能不能透视,微乐自建房辅助软件,必备透视(有挂解惑)-哔哩哔哩1、玩家可以在...
透视解迷!wpk私人局辅助是真... 透视解迷!wpk私人局辅助是真的吗,wpk辅助器是真的吗(透视)确实存在有软件(哔哩哔哩)透视方法中...
连日来!智星德州插件最新版本更... 连日来!智星德州插件最新版本更新内容详解,微信小程序微乐破解器,解密脚本(竟然有挂)-哔哩哔哩1、不...
透视模拟器!wepoker新号... 透视模拟器!wepoker新号好一点吗,微乐智能辅助软件是真的吗,揭幕透视(讲解有挂)-哔哩哔哩;1...
脚本科普!wepoker透视方... 脚本科普!wepoker透视方法,wepoker辅助脚本(透视)都是真的有app(哔哩哔哩)脚本科普...