gpt4 book ai didi

android - 监听 Android 中的布局变化

转载 作者:搜寻专家 更新时间:2023-11-01 09:15:53 26 4
gpt4 key购买 nike

如何在布局过程完成时收到通知?是否有类似 onLayoutFinished() 的东西,我可以在某处实现或覆盖?

来自View文档:

Layout is a two pass process: a measure pass and a layout pass. The measuring pass is implemented in measure(int, int) and is a top-down traversal of the view tree. Each view pushes dimension specifications down the tree during the recursion. At the end of the measure pass, every view has stored its measurements. The second pass happens in layout(int, int, int, int) and is also top-down. During this pass each parent is responsible for positioning all of its children using the sizes computed in the measure pass.

我想要的是在“第二遍”完成后执行一些逻辑。特别是,我想对一个 View 进行一些更改,然后根据第一个 View 的框架(位置和大小)对另一个 View 进行更改。

最佳答案

您可以简单地覆盖 onLayout() 并在调用 super.onLayout() 之后执行您需要执行的任何操作。您还可以重写 onSizeChanged(),仅当布局过程更改 View 的坐标/大小时才会调用它。

关于android - 监听 Android 中的布局变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4716194/

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