【问题标题】:What is unit of parameter value in onMeasure(int widthMeasureSpec, int heightMeasureSpec) method of View Class?View Class 的 onMeasure(int widthMeasureSpec, int heightMeasureSpec) 方法中参数值的单位是什么?
【发布时间】:2011-09-06 11:25:15
【问题描述】:

任何机构都可以让我知道参数的单位是什么 onMeasure(int widthMeasureSpec, int heightMeasureSpec) 这个视图类方法。

我打印日志,它分别返回 1073742144,-2147483251。

【问题讨论】:

    标签: android view


    【解决方案1】:

    该值是模式和大小的组合。使用View.MeasureSpec.getMode(widthMeasureSpec) 获取模式(MeasureSpec.EXACTLYMeasureSpec.AT_MOSTMeasureSpec.UNSPECIFIED 之一);您可能想知道View.MeasureSpec.getSize(widthMeasureSpec),以像素为单位的大小。

    另请参阅source code of MeasureSpec

    【讨论】:

    • 谢谢,所以当 onMeasure(...) 调用它时,它会返回以像素为单位的屏幕大小...我说的对吗?
    • 是的,onMeasure() 和所有其他与测量相关的函数都适用于像素。
    猜你喜欢
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    相关资源
    最近更新 更多