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

相关内容

热门资讯

透视解密!aapoker透视怎... 透视解密!aapoker透视怎么用,aapoker透视脚本下载(透视)好像真的有攻略(哔哩哔哩)1、...
不少玩家反映!wepoker私... 不少玩家反映!wepoker私人局有透视吗,微乐小程序黑科技辅助工具2026最新推荐,普及脚本(有挂...
记者获悉!wepoker辅助器... 记者获悉!wepoker辅助器,微信微乐辅助脚本平台,必备脚本(有人有挂)-哔哩哔哩1、wepoke...
脚本科普!wepoker辅助器... 脚本科普!wepoker辅助器激活码,wepoker有什么规律(透视)都是真的有器(哔哩哔哩)1、进...
透视实锤!wepokerplu... 透视实锤!wepokerplus辅助,微信小程序微乐辅助,关于脚本(有挂助手)-哔哩哔哩1、让任何用...
透视总结!hhpoker辅助软... 透视总结!hhpoker辅助软件,hhpoker是真的假的(透视)其实有挂(哔哩哔哩)1、不需要AI...
为切实保障!淘宝买wepoke... 为切实保障!淘宝买wepoker透视有用吗,微乐贵阳捉鸡麻将开挂,科普脚本(今日头条)-哔哩哔哩淘宝...
脚本详情!hh poker辅助... 脚本详情!hh poker辅助有用吗,hhpoker怎么防作必弊(透视)切实有脚本(哔哩哔哩)1、点...
透视ai!福建大菠萝万能辅助器... 透视ai!福建大菠萝万能辅助器,微乐云南小程序修改器ios,开挂脚本(有挂技术)-哔哩哔哩1、该软件...
脚本推荐!wpk私人局有透视吗... 脚本推荐!wpk私人局有透视吗,有哪些免费的wpk作必弊码(透视)真是真的是有工具(哔哩哔哩)1、许...