gpt4 book ai didi

android - getMeasuredHeight 和 getHeight 有什么区别

转载 作者:IT王子 更新时间:2023-10-28 23:45:50 34 4
gpt4 key购买 nike

我尝试在 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com