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宽高比,以便系统可以更好地管理多个窗口之间的相同宽高比。
  • 构建一个窗口布局信息对象,将其与活动选项绑定,并启

相关内容

热门资讯

盘点一款!wepower德州设... 盘点一款!wepower德州设置,governorofpoker3有挂,详细教程(有挂介绍)-哔哩哔...
透明挂透视!(wePOke)软... 透明挂透视!(wePOke)软件透明挂,扑克王辅助工具,详细教程(有挂规律)-哔哩哔哩;wePOke...
玩家必看分享!(wepOkE)... 《wepOkE软件透明挂》是一款多人竞技的wepOkE辅助透视游戏,你将微扑克对手来到同一个战场,为...
专业讨论!德州扑克ai机器人,... 《专业讨论!德州扑克ai机器人,(wepOkE)软件透明挂,详细教程(有挂透明)-哔哩哔哩》 德州扑...
透视ai代打!德州ai辅助神器... 透视ai代打!德州ai辅助神器下载,pokermaster有外挂,详细教程(有挂技巧)-哔哩哔哩;玩...
玩家必看教程!poker有外挂... 玩家必看教程!poker有外挂,aa poker有外挂,详细教程(有挂规律)-哔哩哔哩;人气非常高,...
透明辅助!(wePOke)软件... 此外,数据分析德州(wePOke)辅助神器app还具备辅助透视行为开挂功能,通过对客户wePOke透...
总算了解!线上wpk到底有外挂... 总算了解!线上wpk到底有外挂,鱼扑克app ai,详细教程(有挂规律)-哔哩哔哩1、点击下载安装,...
必备攻略!轰趴大菠萝十三水有外... 必备攻略!轰趴大菠萝十三水有外挂,(wepoke)软件透明挂,详细教程(有挂介绍)-哔哩哔哩;原来确...
2024教程!(wepOke)... 2024教程!(wepOke)软件透明挂,wepower有辅助器,详细教程(有挂教学)-哔哩哔哩准备...