Android 中 Activity 的根视图是否事先了解将加载到其中的子视图?
有没有什么方法可以在根视图或其子视图膨胀之前查询活动的根视图以获取其所有子视图?我想我正在寻找的是一个视图是否提前知道它在膨胀之前会拥有哪些子级,以及我是否可以以某种方式获取该列表。我意识到这很奇怪,但我认为这将帮助我进行一些非常规的自动化测试。我还没有在 API 中找到这样的东西,所以我希望社区知道一些有用的东西。
谢谢!
Is there any way to query a root view of an activity for all of its child views even before the root view or its children have been inflated? I guess what I'm looking for is whether a view knows ahead of time what children it will have before it gets inflated, and can I get that list in some way. Bizarre I realize, but I think it will help me with some unconventional automation testing I'm working on. I haven't found anything in the API like this, so I'm hoping the community knows something spiff that will help.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此表示怀疑。
在
onCreate()
中调用setContentView()
之前,Activity
对其视图一无所知(它只有根窗口) > 方法。有一个名为
ViewStub
的构造,它允许您延迟扩展 UI 的某些部分,直到您需要它们为止,但即便如此,在您扩展子视图之前,您实际上也不知道有关子视图的任何信息。其他可能感兴趣的是
ViewTreeObserver
< /a> 及其子类。这允许您在视图层次结构发生更改时收到通知。您的测试自动化听起来确实非常规。有趣:)
I doubt it.
An
Activity
doesn't have any knowledge of its view (it just has its root window) until you callsetContentView()
in theonCreate()
method.There is a construct called
ViewStub
which allows you to delay inflating certain parts of the UI until you need them, but even then you wouldn't actually know anything about the child views until you inflate it.Something else that may be of interest is the
ViewTreeObserver
and its subclasses. That allows you to receive notifications when a view hieararchy is changing.Your test automation certainly does sound unconventional. Intriguing :)