AndroidR(Api30)中WindowInsetListener会使偏移量翻倍。
创始人
2024-10-10 00:31:49
0

在Android R中,WindowInsetListener在布局中使用时会使偏移量增加两倍。为了解决这个问题,需要在代码中使用以下方法来获得将偏移量倍增的正确值。

  1. 在布局文件中设置fitsSystemWindows属性为true:

    

  1. 在代码中使用以下方法来获得修正后的偏移量值:
ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() {
    @Override
    public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
        int topInset = insets.getSystemWindowInsetTop() / 2;
        int bottomInset = insets.getSystemWindowInsetBottom() / 2;
        int leftInset = insets.getSystemWindowInsetLeft() / 2;
        int rightInset = insets.getSystemWindowInsetRight() / 2;
        return insets.inset(leftInset, topInset, rightInset, bottomInset);
    }
});

通过使用fitsSystemWindows属性来设置偏移量,在代码中使用以上方法来获取正确的偏移量值。这将解决WindowInsetListener在Android R中倍增偏移量的问题。

相关内容

热门资讯

透视透视“德州真人透视脚本”透... 透视透视“德州真人透视脚本”透视辅助app(原来是有挂)德州真人透视脚本软件透明挂微扑克wpk插件教...
透视计算!德普之星辅助器,(德... 透视计算!德普之星辅助器,(德普之星)切实是真的有挂,微扑克教程(有挂工具)1、游戏颠覆性的策略玩法...
透视透视!pokemmo内置修... 透视透视!pokemmo内置修改器,德州局透视脚本下载安装最新版本,黑科技教程(有挂介绍)运德州局透...
透视美元局!如何下载德普之星辅... 透视美元局!如何下载德普之星辅助软件,德普之星透视辅助软件,靠谱教程(有挂脚本);1、首先打开如何下...
透视插件“pokemmo脚本最... 透视插件“pokemmo脚本最新版”透视辅助插件(果然有挂)1、玩家可以在pokemmo脚本最新版软...
透视模拟器“pokemmo脚本... 透视模拟器“pokemmo脚本辅助下载”透视辅助助手(确实存在有挂)1、pokemmo脚本辅助下载系...
透视安卓版!德普之星的辅助工具... 透视安卓版!德普之星的辅助工具介绍,德普之星辅助器app,规律教程(有挂规律)透视安卓版!德普之星的...
透视工具“xpoker辅助怎么... 透视工具“xpoker辅助怎么用”透视辅助工具(一直是有挂)1、完成xpoker辅助怎么用透视辅助安...
透视挂!德普之星透视辅助软件下... 透视挂!德普之星透视辅助软件下载,(德普之星)其实真的有挂,力荐教程(有挂黑科技)1、该软件可以轻松...
透视系统“哈糖大菠萝挂法”透视... 透视系统“哈糖大菠萝挂法”透视辅助插件(原来有挂)1、不需要AI权限,帮助你快速的进行哈糖大菠萝挂法...