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辅助码,菠萝德普辅助器免费版在哪里,方案教程(有挂教学)-哔哩哔哩1、...
透视透视挂!wepoker透视... 透视透视挂!wepoker透视最简单三个步骤,wepoker有脚本吗,技法教程(有人有挂)-哔哩哔哩...
透视私人局!hhpoker有没... 您好,wepoker私人局有透视吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【1367043...
透视肯定!德扑圈透视挂,wep... 透视肯定!德扑圈透视挂,wepoker怎么发冤家牌,讲义教程(有挂解惑)-哔哩哔哩亲,关键说明,we...
透视透视!hhpoker是真的... 透视透视!hhpoker是真的假的,aapoker脚本怎么用,诀窍教程(有挂神器)-哔哩哔哩aapo...
透视真的!hhpoker俱乐部... 透视真的!hhpoker俱乐部是干嘛的,hhpoker辅助挂,讲义教程(有挂方针)-哔哩哔哩hhpo...
透视能赢!werplan辅助软... 透视能赢!werplan辅助软件,德扑之心免费透视,方案教程(讲解有挂)-哔哩哔哩1、任何德扑之心免...
透视神器!wepoker有没有... 透视神器!wepoker有没有透视方法,德普之星私人局透视,阶段教程(确实有挂)-哔哩哔哩wepok...
透视了解!红龙poker辅助指... 透视了解!红龙poker辅助指令,aapoker怎么开辅助器,模块教程(今日头条)-哔哩哔哩1、aa...
透视有挂!德州来玩辅助器,wp... 透视有挂!德州来玩辅助器,wpk俱乐部辅助器,指南教程(有挂透视)-哔哩哔哩1、不需要AI权限,帮助...