解决AndroidAutoLayout无法适配18:9 全面屏

随着人们对大屏手机需求的变化,Android全面屏 越来越多

解决AndroidAutoLayout无法适配18:9 全面屏_第1张图片

解决AndroidAutoLayout无法适配18:9 全面屏_第2张图片


AutoLayout这个以往用于简单适配屏幕像素的框架存在着严重变形的问题

鸿洋的AutoLayout项目地址 已经停止更新了

https://github.com/hongyangAndroid/AndroidAutoLayout

以下为宽高比缩略图

解决AndroidAutoLayout无法适配18:9 全面屏_第3张图片

变形效果 左为正常需求  右边为全面屏

解决AndroidAutoLayout无法适配18:9 全面屏_第4张图片解决AndroidAutoLayout无法适配18:9 全面屏_第5张图片


解决方案 修改AutoLayoutConfig init方法

将高度只按宽度同比例进行适配 (AutoLayout里面Meta配置为1080*1920 16:9 全面屏为18:9)

源码:

public void init(Context context) {
        getMetaData(context);
        int[] screenSize = ScreenUtils.getScreenSize(context, useDeviceSize);
        mScreenWidth = screenSize[0];
        mScreenHeight = screenSize[1];
        }


    }
修改为以下代码
public void init(Context context) {
        getMetaData(context);

        int[] screenSize = ScreenUtils.getScreenSize(context, useDeviceSize);
        mScreenWidth = screenSize[0];
        //取宽度作为基准
        float mDesignRate = 1.0f * mDesignHeight / mDesignWidth;
        float screenRate = 1.0f * screenSize[1] / screenSize[0];
        if (screenRate > mDesignRate) {
            mScreenHeight = (int) (screenSize[1] * (mDesignRate / screenRate));
        } else {
            mScreenHeight = screenSize[1];
        }


    }

这个修改方案并不是非常好,比如这是一个长屏幕   原来的autolayout布局是刚好到底部   蓝色我代码修改后的是适配  刚好剩下白色区域 但是变形的问题解决了解决AndroidAutoLayout无法适配18:9 全面屏_第6张图片 如果有更好的方案可以邮箱我

[email protected]

你可能感兴趣的:(java,android,移动开发,UI设计,遇到问题)