Android技术知识Android 适配的那些事Android开发经验谈

Android 全面屏黑边适配

2019-02-13  本文已影响11人  木木Jump

问题:

全面屏底部会出现黑边

原因:

全面屏宽高比例比较特殊,不是之前的16:9。例如小米mix2s,屏幕宽高比是18:9。Android默认支持的最大宽高比例是1.86,小于全面屏手机的宽高比例。所有如果全面屏手机上的应用没有做适配,底部就会出现黑边。

解决方案:

<application 
        ...
        android:resizeableActivity="true">

targetSdkVersion 24及以上默认为true,可以不用设置该属性值。同时该方案会开启应用分屏功能,注意界面适配问题。

设置方法:
1.在AndroidManifest的Application标签下面增加下面一段代码

<meta-data
            android:name="android.max_aspect"
            android:value="2.3"/>

2.代码动态设置max_aspect值:

ApplicationInfo applicationInfo = null;
        try {
            applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if(applicationInfo == null){
            throw new IllegalArgumentException(" get application info = null, has no meta data! ");
        }
        applicationInfo.metaData.putString("android.max_aspect", "2.3");

参考文章:
Android APP适配全面屏手机的技术要点

上一篇 下一篇

猜你喜欢

热点阅读