安卓机水滴屏iphoneX全面屏 适配 实践

方案一:

android studio 工程

在应用的AndroidManifest.xml中增加meta-data属性

此属性不仅可以针对Application生效,也可以对Activity配置生效。弊端:对Application生效,意味着该应用的所有页面,系统都不会做竖屏场景的特殊下移或者是横屏场景的右移特殊处理,也不能针对某页面做特殊处理。

       <!-- Android O刘海适配 start -->
        <!-- 华为 -->
        <meta-data
            android:name="android.notch_support"
            android:value="true" />
        <!-- 华为 -->
        
        <!-- 小米 -->
        <meta-data
            android:name="notch.config"
            android:value="portrait|landscape" />
        <!-- 小米 -->
        <!-- Android O刘海适配 end -->

        <!-- Android全面屏全屏 start -->
        <meta-data
            android:name="android.max_aspect"
            android:value="2.2" />
        <!-- Android全面屏全屏 end -->
 

cocos 游戏内


游戏背景考虑按全面屏的分辨率去做

同时可以在UI上加上widget组件,根据宽高比 以及机型 判断 是否存在刘海区域 动态调整部分ui布局

如果游戏背景 无法适配 全部android机型 可以考虑 fit hight (分辨率执行将内容的高度缩放为屏幕的高度,并按比例缩放其宽度)

 

/Applications/CocosCreatorv1.10.3.app/Contents/Resources/engine/cocos2d/core/platform/CCView.js

/**
     * Sets the resolution policy with designed view size in points.<br/>
     * The resolution policy include: <br/>
     * [1] ResolutionExactFit       Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.<br/>
     * [2] ResolutionNoBorder       Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.<br/>
     * [3] ResolutionShowAll        Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.<br/>
     * [4] ResolutionFixedHeight    Scale the content's height to screen's height and proportionally scale its width<br/>
     * [5] ResolutionFixedWidth     Scale the content's width to screen's width and proportionally scale its height<br/>
     * [cc.ResolutionPolicy]        [Web only feature] Custom resolution policy, constructed by cc.ResolutionPolicy<br/>
     * @method setDesignResolutionSize
     * @param {Number} width Design resolution width.
     * @param {Number} height Design resolution height.
     * @param {ResolutionPolicy|Number} resolutionPolicy The resolution policy desired
     */
    setDesignResolutionSize: function (width, height, resolutionPolicy) {
        // Defensive code
        if( !(width > 0 || height > 0) ){
            cc.logID(2200);
            return;
        }

        this.setResolutionPolicy(resolutionPolicy);
        var policy = this._resolutionPolicy;
        if (policy) {
            policy.preApply(this);
        }

        // Reinit frame size
        if (cc.sys.isMobile)
            this._adjustViewportMeta();

        // Permit to re-detect the orientation of device.
        this._orientationChanging = true;
        // If resizing, then frame size is already initialized, this logic should be improved
        if (!this._resizing)
            this._initFrameSize();

        if (!policy) {
            cc.logID(2201);
            return;
        }

        this._originalDesignResolutionSize.width = this._designResolutionSize.width = width;
        this._originalDesignResolutionSize.height = this._designResolutionSize.height = height;

        var result = policy.apply(this, this._designResolutionSize);

        if(result.scale && result.scale.length === 2){
            this._scaleX = result.scale[0];
            this._scaleY = result.scale[1];
        }

        if(result.viewport){
            var vp = this._viewPortRect,
                vb = this._visibleRect,
                rv = result.viewport;

            vp.x = rv.x;
            vp.y = rv.y;
            vp.width = rv.width;
            vp.height = rv.height;

            vb.x = -vp.x / this._scaleX;
            vb.y = -vp.y / this._scaleY;
            vb.width = cc.game.canvas.width / this._scaleX;
            vb.height = cc.game.canvas.height / this._scaleY;
            cc._renderContext.setOffset && cc._renderContext.setOffset(vp.x, -vp.y);
        }

        // reset director's member variables to fit visible rect
        var director = cc.director;
        director._winSizeInPoints.width = this._designResolutionSize.width;
        director._winSizeInPoints.height = this._designResolutionSize.height;
        policy.postApply(this);
        cc.winSize.width = director._winSizeInPoints.width;
        cc.winSize.height = director._winSizeInPoints.height;

        if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
            // reset director's member variables to fit visible rect
            director.setGLDefaultValues();
        }
        else if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
            cc.renderer._allNeedDraw = true;
        }

        this._originalScaleX = this._scaleX;
        this._originalScaleY = this._scaleY;
        cc.visibleRect && cc.visibleRect.init(this._visibleRect);
    },

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mrwql

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值