Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android 7.0适配 #31

Open
ZhengFat opened this issue Feb 7, 2017 · 3 comments
Open

android 7.0适配 #31

ZhengFat opened this issue Feb 7, 2017 · 3 comments

Comments

@ZhengFat
Copy link

ZhengFat commented Feb 7, 2017

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

@yhaolpz
Copy link

yhaolpz commented Aug 7, 2017

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

@yeyueduxing
Copy link

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
Copy link

yhaolpz commented Aug 30, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants