Android 什么时候调用 onSizeChanged()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3526148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
when is onSizeChanged() called?
提问by iman453
Is onSizeChanged()
called once the user touches some part of the screen?
onSizeChanged()
一旦用户触摸屏幕的某个部分就被调用?
I'm confused about the order in which onDraw()
, onMeasure()
and onSizeChanged()
are called.
我对调用onDraw()
,onMeasure()
和的顺序感到困惑onSizeChanged()
。
回答by Colin Hebert
Android doesn't know the real size at start, it needs to calculate it. Once it's done, onSizeChanged()
will notify you with the real size.
Android 一开始不知道实际大小,它需要计算它。完成后,onSizeChanged()
将通知您实际尺寸。
onSizeChanged()
is called once the size as been calculated. Events don't have to come from users all the time. In this example when android change the size, onSizeChanged()
is called. Same thing with onDraw()
, when the view should be drawn onDraw()
is called.
onSizeChanged()
一旦计算出大小,就会调用。事件不必总是来自用户。在这个例子中,当 android 改变大小时,onSizeChanged()
被调用。与onDraw()
, 何时应该绘制视图相同onDraw()
。
onMeasure()
is called automatically right after a call to measure()
onMeasure()
调用后立即自动调用 measure()