何时使用 Android PopupWindow 与 Dialog
我不清楚何时使用 PopupWindow 与 Dialog。任何见解将不胜感激。谢谢。
I'm unclear about when to use PopupWindow vs Dialog. Any insight would be much appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它们都使用 addView() 方法以及各种 windowManager 方法。两者在这方面是相似的。
对话框似乎带有更多内置的交互功能,例如已经包含在基类中的处理程序和按钮,而 PopupWindows 带有更多内置方法来将它们定位在屏幕上。
我认为它们中的每一个都可以做完全相同的事情,但是在两者之间进行选择对于程序员来说将是一个方便的问题,因为您想如何使用对象。我不是计算机科学的博士,但根据我在各自的类定义中看到的情况,我认为两者之间的处理时间没有显着差异。
我的建议:如果您想更好地控制视图在显示屏上的显示位置,请使用 PopupWindow。如果您想在视图之间添加更多控制和反馈,请使用对话框。如果您像我一样想要掌控一切,我会建议使用 PopupWindow,因为它需要覆盖的用户明显的默认方法较少。
They both use the addView() method along with various windowManager methods. The two are similar in that regard.
Dialogs seem to come with more built-in features for interaction, such as handlers and buttons already included in the base class, while PopupWindows come with more built-in methods for positioning them about the screen.
I think that each of them can do exactly the same as the other, but choosing between the two will be a matter of convenience to the programmer with regards to how you want to use the Object. I'm not a phD in computer science, but I do not think there is a significant difference in processing time between the two based on what I saw in their respective class definitions.
My advice: If you want to have greater control over where your View appears on the display, use a PopupWindow. If you want to add more control and feedback between your View then use a Dialog. If you, like me, want master control over everything, I would suggest a PopupWindow since it has fewer user-evident default methods to override.
我认为,您应该使用 Dialog 进行简单的用户交互(是,否)。
我通常使用 Dialog 进行简单的用户交互,使用 WindowPopup 进行更复杂的视图。
WindowPopup 的一个示例是 AutoCompleteTextView。
希望有帮助。
I think, that you should use Dialog for simple user interaction (YES,NO).
I usually use Dialog for simple user interaction and WindowPopup for a little bit more complex view.
One example of WindowPopup is AutoCompleteTextView.
Hope it helps.
我认为当您需要在继续下一步之前采取行动时应该使用对话框。它永远不会覆盖屏幕,并且始终作为模态事件调整中心对齐。
另一方面,PopupWindow 可以根据位置设置灵活地调整屏幕中任何位置的信息,如粘性页脚、粘性页眉、左侧、右侧、中心等。
对于显示信息来说,这是一个不错的选择,因为也有动画功能。
简而言之,要以最少的操作显示信息,请使用 PopupWindow,要控制下一步继续进行的操作,请使用 Dialog。
I think Dialog should use when you need to take action before proceed to continue next. It never cover the screen and always adjust center aligned as modal event.
On other side, PopupWindow has flexibility to adjust information anywhere in the screen as position wise like sticky footer, sticky header, on left, right, center etc. as per location set.
For Showing Information it's good option as there is facility to animate also.
In short, For Showing Information with minimal action go with PopupWindow and for controlled action to proceed next go with Dialog.