分享

View 的两对大小 getWidth getHeight getMeasuredWidth getMeasuredHeight

 拨开云雾见天日 2013-01-24
对于View的两个大小的API,以前有很多迷惑,不知道具体其含义,今天在看google官方文档的时候看到如下描述,
终于恍然大悟。现记录如下:

The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.

The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent. The measured dimensions can be obtained by calling getMeasuredWidth() andgetMeasuredHeight().

The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height can be obtained by calling getWidth() and getHeight().

大概意思就是getWidth和getHeight获取的是View当前实际显示的大小,而getMeasured相关的函数则获取的是View在父类中计算的需要占用的大小。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约