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免费脚本弱密码,wepokerplus到底是挂了吗,透明挂教程(有挂透视);...
热点推荐!wepoker怎么获... 此外,数据分析德州(wepoker辅助器软件下载)辅助神器app还具备辅助透视行为开挂功能,通过对客...
玩家必看科普!哈糖大菠萝软件下... 玩家必看科普!哈糖大菠萝软件下载,aapoker辅助软件合法吗,曝光教程(有挂透视)是一款可以让一直...
安装程序教程!德州圈脚本,hh... 安装程序教程!德州圈脚本,hhpoker开挂教程,德州论坛(有挂辅助)是一款可以让一直输的玩家,快速...
一分钟了解!wejoker开挂... 一分钟了解!wejoker开挂,wepoker透视方法,必赢方法(有挂辅助);最新版2024是一款经...
带你了解!德扑HHpoker有... 带你了解!德扑HHpoker有挂吗,wepoker辅助器怎么弄,安装教程(有挂攻略)是一款可以让一直...
玩家交流!werplan免费挂... 玩家交流!werplan免费挂下载,hh poker辅助器先试用,总结教程(有挂神器);亲真的是有正...
传递经验!wepoker辅助器... 1、传递经验!wepoker辅助器安装包定制,hhpoker可以控制吗,线上教程(有挂技巧);详细教...
分享一款!aapoker插件下... 1、分享一款!aapoker插件下载,德州局HHpoker透视脚本,2025新版教程(有挂教程)(U...
总算了解!hhpoker破解工... 总算了解!hhpoker破解工具,wepoker插件功能辅助器,细节揭秘(有挂软件);科技安装教程;...