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

相关内容

热门资讯

不少玩家反映!newpoker... 不少玩家反映!newpoker脚本(透视)悟空大厅辅助看牌(本来是真的辅助软件)-哔哩哔哩1、完成悟...
迎来新发展!如何判断wpk辅助... 迎来新发展!如何判断wpk辅助软件的真假(透视)海贝之城有辅助吗(其实是有辅助插件)-哔哩哔哩1、用...
今天下午!德州透视插件(透视)... 今天下午!德州透视插件(透视)樱花之盛挂(竟然存在有辅助辅助器)-哔哩哔哩樱花之盛挂脚本下载中分为三...
透视好友!wepokerh5破... 透视好友!wepokerh5破解(透视)微乐河南小程序微乐辅助脚本(好像存在有辅助软件)-哔哩哔哩1...
透视神器!we-poker辅助... 透视神器!we-poker辅助软件教程(透视)新广西老友辅助(切实是有辅助下载)-哔哩哔哩新广西老友...
透视总结!哈糖大菠萝能开挂吗(... 透视总结!哈糖大菠萝能开挂吗(透视)多乐破解游戏盒子破解版(都是有辅助软件)-哔哩哔哩1、多乐破解游...
围绕透视问题!aapoker能... 您好,南通长牌有挂吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...
据目击者称!wepoker代打... 据目击者称!wepoker代打辅助(透视)微信闲来辅助神器免费(果然存在有辅助插件)-哔哩哔哩小薇(...
近日!hhpoker透视脚本视... 近日!hhpoker透视脚本视频(透视)微乐卡五星祈福有用吗(好像真的是有辅助平台)-哔哩哔哩1、玩...
透视好友!wepoker透视有... 透视好友!wepoker透视有用吗(透视)拱趴大菠萝9人场技巧(真是真的是有辅助插件)-哔哩哔哩1、...