Giter Club home page Giter Club logo

Comments (2)

SMAXLYB avatar SMAXLYB commented on August 27, 2024

大佬,getChildMeasureSpec()中第一个case中有个疑问

    //如果父容器的模式是Exactly即确定的大小
    case MeasureSpec.EXACTLY:
    	//子View的高度或宽度>0说明其实一个确切的值,因为match_parent和wrap_content的值是<0的
        if (childDimension >= 0) {
            resultSize = childDimension;
            resultMode = MeasureSpec.EXACTLY;
            //子View的高度或宽度为match_parent
        } else if (childDimension == LayoutParams.MATCH_PARENT) {
           ...
        }

这里父view有确定的大小(size),子view自己也设置了大小(childDimension),为啥最后resultSize =childDimension,难道不应该先判断一下childDimension是否会大于父view的大小,childDimension很有可能会大于size,果断的取childDimension岂不是存在子view长度或者宽度溢出的情况:thinking:,而且上面也说到了:

EXACTLY:父元素决定子元素的确切大小,子元素将被限定在给定的边界里而忽略它本身大小;

望大佬解惑:pray:

from blogs.

mzzdxt avatar mzzdxt commented on August 27, 2024

EXACTLY:父元素决定子元素的确切大小,子元素将被限定在给定的边界里而忽略它本身大小;

望大佬解惑🙏

看源码发现父容器不管在什么测量模式下,只要子元素有确切的尺寸值(非match_parent和wrap_content),都会把这个值设置为最终测量值,我理解是Framework层为了尊重开发者意见,可以用demo试一下,感觉这里的tip确实有点歧义

from blogs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.