- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我不确定 onAttachedToWindow
的用法。
我的问题基本上是关于 documentation 的.其中提到:
[...] it may be called any time before the first onDraw -- including before or after onMeasure(int, int)
我知道什么:
什么时候在 onMeasure
之前调用,什么时候在之后调用。
背后的故事:
我在 onAttachedToWindow
中添加 OnGlobalLayoutListener
并在 onDetachedFromWindow
中删除它。因为在将 View 添加到窗口时处理布局对我来说是某种逻辑。但我担心如果尚未添加监听器,第一个 onGlobalLayout 调用会丢失。 (因为onMeasure一般发生在布局的时候)
如果有人有更好的方法来解决我的问题,请随时给我提示。
最佳答案
文档是正确的,你不应该依赖于 onWindowAttach/Detach
与 onMeasure
或 onLayout
pass 同步。
如果您的 View
类对父层次结构的更改感兴趣,我建议不要采用这种设计。父 UI 应通知 subview 层次结构更改。因此,OnGlobalLayoutListener
最好由封闭的 UI 类使用。
此外,View
类有 onSizeChanged()
您可以覆盖它以检测它何时被测量。
关于android - Layouting Process什么时候调用onAttachedToWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758969/
我对 android Activity 生命周期很感兴趣,我想获得比广泛可用的基础(onCreate->onStart->onResume)更详细的描述/文档/引用 one . 我的需求来自于意识到从
我在 Activity 中使用渐变作为背景。在某些 Android 设备上,它看起来不像在 Photoshop 中那样好和流畅,要解决这个问题,有人告诉我使用 onAttachedToWindow()
有一种方法可以在调用 onAttachedToWindow 并且窗口类型为 keyguard 时隐藏状态栏或禁用它?我在我的 Activity 课上尝试过这个: 这是 onCreate public
我有时看到人们使用 Activity.onAttachedToWindow 方法,但就我个人而言,我从未使用过它。在阅读它的文档时,我觉得它与 onStart() 几乎相同。 我假设的一件事是:onA
我收到从 SurfaceView.onAttachedToWindow 引发的异常。看起来 SurfaceView 正在尝试引用 mParent,但它是 null。有谁知道为什么不设置父级但会调用 o
我相信 onAttachedToWindow() 在 onCreate() 的 setContentView(R.layout.myLayout.xml) 是叫。那么我是否可以假设在 Activity
什么是 Flutter 等效于 Android 的 View::onAttachedToWindow 和 View::onDetachedFromWindow? 基本上,在 Flutter 中,如何确
我是一名优秀的程序员,十分优秀!