Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Professional Android 4 Application Development 的第 4 章,它告诉我大小值和模式都是从传递给自定义视图的 onMeasure() 方法的 widthMeasureSpec 和 heightMeasureSpec 值中提取的。除了整数原语之外,那些不必是其他数据结构来实现这一点吗?这些整数的编码方式是否可以手动覆盖它们的值?
模式为 EXACTLY、AT_MOST 或 UNSPECIFIED。所以从技术上讲,只需要两位来存储模式。如果您查看它们的值,确切地说是 0x80000000,AT_MOST 是 0x40000000,而 UNSPECIFIED 是 0x00000000。他们正在获取 int 的前两位并将它们与大小进行 ORing 以获得 MeasureSpec。这可能是早期 Android 的遗留问题,当时设备确实没有太多内存,所以他们尽可能地节省内存。