android - getMeasuredHeight 和 getHeight 有什么区别

标签 android view width

我尝试在 onGlobalLayout 中调用 View.getMeasuredHeightView.getHeight。两者都给了我相同的结果。

我想知道,在什么情况下它们的值会有所不同?有没有例子可以证明这一点?

我尝试在谷歌中搜索。第一个结果似乎与这个问题无关:Android: How to get a custom View's height and width?

最佳答案

当您使用 View 时,它会对其子元素施加一定的大小限制。这些限制可能会阻止子元素占用它想要的空间量。

documentation for the View class对这些属性的描述如下:

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 (see Layout for more details.) The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().

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().

另请参阅:http://developer.android.com/guide/topics/ui/how-android-draws.html

关于android - getMeasuredHeight 和 getHeight 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19524182/

相关文章:

Java Eclipse Android 初学者问题 - 如何添加库或链接文件夹。初学者引用

java - Google 应用引擎端点在哪里

sql - 在 PL/SQL 中的 View 上触发

android - viewpager 上方的 Viewstub ()

css - HTML Div 宽度溢出 : Auto?

css - 悬停时,CSS 菜单中的标题会更改宽度

android - 添加Maven仓库报错——android.support.v7.widget.AppcompatTextView无法实例化

android - Android 中的 AdMob 集成

postgresql - 重命名 View 中的列 : bug or feature?

css - 内联样式 react 元素宽度