When to use Android PopupWindow vs Dialog

南楼画角 提交于 2019-12-18 03:02:05

问题


I'm unclear about when to use PopupWindow vs Dialog. Any insight would be much appreciated. Thanks.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/4710361/when-to-use-android-popupwindow-vs-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!