gpt4 book ai didi

android - getheight() 和 getmeasuredheight() 的区别

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:00:13 24 4
gpt4 key购买 nike

我正在经历这个http://developer.android.com/guide/topics/ui/declaring-layout.html当我看到一条线表明高度可以但不一定与测量高度不同时,我在想测量高度如何与布局高度不同。

最佳答案

方法 View#getMeasuredWidth()View#getMeasuredHeight() 表示 View 想要的尺寸,在布局中的所有 View 被计算和放置之前屏幕。

View#onMeasure(int, int)View#onLayout(boolean, int, int, int, int) 之后,可以更改 View 测量以适应所有内容.然后可以通过 View#getWidth()View#getHeight() 访问这些(可能的)新值。

来自View class reference :

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

关于android - getheight() 和 getmeasuredheight() 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27673970/

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