hongyangAndroid / android-percent-support-extend

a extends lib for android-percent-support(Google百分比布局库的扩展)
http://blog.csdn.net/lmj623565791/article/details/46767825
Apache License 2.0
1.81k stars 501 forks source link

android 7.0适配 #31

Open ZhengFat opened 7 years ago

ZhengFat commented 7 years ago

最近测试机更新了7.0 之前合适的布局除了问题。请问是不兼容7.0嘛?

yhaolpz commented 7 years ago

同问,Android 7.0 遇到 layout_marginLeftPercent 属性失效问题,低于 7.0 正常。

yeyueduxing commented 7 years ago

7.0适配的话,修改下源码PercentLayoutHelperl类的方法fillMarginLayoutParams就可以了 public void fillMarginLayoutParams(ViewGroup.MarginLayoutParams params, int widthHint, int heightHint) { fillLayoutParams(params, widthHint, heightHint);

        // Preserver the original margins, so we can restore them after the measure step.
        mPreservedParams.leftMargin = params.leftMargin;
        mPreservedParams.topMargin = params.topMargin;
        mPreservedParams.rightMargin = params.rightMargin;
        mPreservedParams.bottomMargin = params.bottomMargin;
        MarginLayoutParamsCompat.setMarginStart(mPreservedParams,
                MarginLayoutParamsCompat.getMarginStart(params));
        MarginLayoutParamsCompat.setMarginEnd(mPreservedParams,
                MarginLayoutParamsCompat.getMarginEnd(params));

        if (leftMarginPercent != null)
        {
            int base = getBaseByModeAndVal(widthHint, heightHint, leftMarginPercent.basemode);
            params.leftMargin = (int) (base * leftMarginPercent.percent);
        }
        if (topMarginPercent != null)
        {
            int base = getBaseByModeAndVal(widthHint, heightHint, topMarginPercent.basemode);
            params.topMargin = (int) (base * topMarginPercent.percent);
        }
        if (rightMarginPercent != null)
        {
            int base = getBaseByModeAndVal(widthHint, heightHint, rightMarginPercent.basemode);
            params.rightMargin = (int) (base * rightMarginPercent.percent);
        }
        if (bottomMarginPercent != null)
        {
            int base = getBaseByModeAndVal(widthHint, heightHint, bottomMarginPercent.basemode);
            params.bottomMargin = (int) (base * bottomMarginPercent.percent);
        }
        if (startMarginPercent != null)
        {
            int base = getBaseByModeAndVal(widthHint, heightHint, startMarginPercent.basemode);
            MarginLayoutParamsCompat.setMarginStart(params,
                    (int) (base * startMarginPercent.percent));
        }
        if (endMarginPercent != null)
        {
            int base = getBaseByModeAndVal(widthHint, heightHint, endMarginPercent.basemode);
            MarginLayoutParamsCompat.setMarginEnd(params,
                    (int) (base * endMarginPercent.percent));
        }
        if (Log.isLoggable(TAG, Log.DEBUG))
        {
            //Log.d(TAG, "after fillMarginLayoutParams: (" + params.width + ", " + params.height
            //        + ")");
        }
        //7.0系统修改下mPreservedParams数据
        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
            mPreservedParams.leftMargin = params.leftMargin;
            mPreservedParams.topMargin = params.topMargin;
            mPreservedParams.rightMargin = params.rightMargin;
            mPreservedParams.bottomMargin = params.bottomMargin;
            MarginLayoutParamsCompat.setMarginStart(mPreservedParams,
                    MarginLayoutParamsCompat.getMarginStart(params));
            MarginLayoutParamsCompat.setMarginEnd(mPreservedParams,
                    MarginLayoutParamsCompat.getMarginEnd(params));
        }

    }
yhaolpz commented 7 years ago

谢谢。


发件人: yeyueduxing notifications@github.com 发送时间: 2017年8月15日 0:02:05 收件人: hongyangAndroid/android-percent-support-extend 抄送: 王英豪; Comment 主题: Re: [hongyangAndroid/android-percent-support-extend] android 7.0适配 (#31)

7.0适配的话,修改下源码PercentLayoutHelperl类的方法fillMarginLayoutParams就可以了 public void fillMarginLayoutParams(ViewGroup.MarginLayoutParams params, int widthHint, int heightHint) { fillLayoutParams(params, widthHint, heightHint);

    // Preserver the original margins, so we can restore them after the measure step.
    mPreservedParams.leftMargin = params.leftMargin;
    mPreservedParams.topMargin = params.topMargin;
    mPreservedParams.rightMargin = params.rightMargin;
    mPreservedParams.bottomMargin = params.bottomMargin;
    MarginLayoutParamsCompat.setMarginStart(mPreservedParams,
            MarginLayoutParamsCompat.getMarginStart(params));
    MarginLayoutParamsCompat.setMarginEnd(mPreservedParams,
            MarginLayoutParamsCompat.getMarginEnd(params));

    if (leftMarginPercent != null)
    {
        int base = getBaseByModeAndVal(widthHint, heightHint, leftMarginPercent.basemode);
        params.leftMargin = (int) (base * leftMarginPercent.percent);
    }
    if (topMarginPercent != null)
    {
        int base = getBaseByModeAndVal(widthHint, heightHint, topMarginPercent.basemode);
        params.topMargin = (int) (base * topMarginPercent.percent);
    }
    if (rightMarginPercent != null)
    {
        int base = getBaseByModeAndVal(widthHint, heightHint, rightMarginPercent.basemode);
        params.rightMargin = (int) (base * rightMarginPercent.percent);
    }
    if (bottomMarginPercent != null)
    {
        int base = getBaseByModeAndVal(widthHint, heightHint, bottomMarginPercent.basemode);
        params.bottomMargin = (int) (base * bottomMarginPercent.percent);
    }
    if (startMarginPercent != null)
    {
        int base = getBaseByModeAndVal(widthHint, heightHint, startMarginPercent.basemode);
        MarginLayoutParamsCompat.setMarginStart(params,
                (int) (base * startMarginPercent.percent));
    }
    if (endMarginPercent != null)
    {
        int base = getBaseByModeAndVal(widthHint, heightHint, endMarginPercent.basemode);
        MarginLayoutParamsCompat.setMarginEnd(params,
                (int) (base * endMarginPercent.percent));
    }
    if (Log.isLoggable(TAG, Log.DEBUG))
    {
        //Log.d(TAG, "after fillMarginLayoutParams: (" + params.width + ", " + params.height
        //        + ")");
    }
    //7.0系统修改下mPreservedParams数据
    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
        mPreservedParams.leftMargin = params.leftMargin;
        mPreservedParams.topMargin = params.topMargin;
        mPreservedParams.rightMargin = params.rightMargin;
        mPreservedParams.bottomMargin = params.bottomMargin;
        MarginLayoutParamsCompat.setMarginStart(mPreservedParams,
                MarginLayoutParamsCompat.getMarginStart(params));
        MarginLayoutParamsCompat.setMarginEnd(mPreservedParams,
                MarginLayoutParamsCompat.getMarginEnd(params));
    }

}

― You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/hongyangAndroid/android-percent-support-extend/issues/31#issuecomment-322392331, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWHERvELOsFoDIiQ7x7WnILPhemZ7frhks5sYUJsgaJpZM4L4_VD.