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官网下载链接,佛手在线大菠萝为什么都输,手段教程(好像是有挂)-哔哩哔哩透视规律!w...
透视靠谱!黑侠破解wepoke... 透视靠谱!黑侠破解wepoker(透视)开挂辅助app(切实真的是有挂)-哔哩哔哩1、黑侠破解wep...
透视系统!德扑圈透视,德州局透... 透视系统!德扑圈透视,德州局透视,要领教程(一贯存在有挂)-哔哩哔哩;1、该软件可以轻松地帮助玩家将...
透视机器人!wepoker私人... 透视机器人!wepoker私人局透视教程(透视)开挂辅助挂(都是真的有挂)-哔哩哔哩1、玩家可以在w...
透视智能ai!wepoker私... 透视智能ai!wepoker私人局俱乐部怎么进,wepoker透视有用吗,练习教程(一贯是真的挂)-...
透视神器!wepoker插件功... 透视神器!wepoker插件功能辅助器(透视)开挂辅助技巧(好像是真的挂)-哔哩哔哩暗藏猫腻,小编详...
透视工具!wepoker底牌透... 透视工具!wepoker底牌透视,wpk透视工作室,妙招教程(一贯真的有挂)-哔哩哔哩透视工具!we...
透视数据!wepoker游戏的... 透视数据!wepoker游戏的安装教程(透视)开挂辅助方法(本来是真的挂)-哔哩哔哩运wepoker...
透视黑科技!wepoker怎么... 透视黑科技!wepoker怎么破解游戏,uupoker有透视吗,方式教程(一贯真的有挂)-哔哩哔哩1...
透视猫腻!智星德州插件2024... 透视猫腻!智星德州插件2024最新版(透视)开挂辅助工具(真是是有挂)-哔哩哔哩一、智星德州插件20...