我应该使用 PopupWindow 还是 DialogFragment 来接受输入? [英] Should I use a PopupWindow or DialogFragment for accepting input?

查看:27
本文介绍了我应该使用 PopupWindow 还是 DialogFragment 来接受输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个带有 3 个微调器和一个 EditText 的弹出窗口.在阅读了许多博客和文章后,我无法决定哪个是最好的选择,PopupWindowDialogFragment.

I am doing a Popup with 3 Spinners and an EditText. After reading many blogs and articles I can't decide which is the best option, PopupWindow or DialogFragment.

标准是:

  1. 与不同 Android 版本的兼容性
  2. 性能

如果有更好的方法,我愿意改变观点.

If there is a better way to do it I am open to change the perspective.

非常感谢.

DialogFragment:

  • 优点:
  • 缺点:

弹出窗口:

  • 优点:
  • 缺点:

结论

DialogFragment 允许您使用更复杂的功能.另一件重要的事情是它更适合平板电脑,因为它允许用户一次打开多个片段.Fragment 是一种更加动态的解决方案,它们是较新 Android 版本的标准.

DialogFragment allows you to use more complex features. Another important thing is that it is more tablet-friendly as it lets user to have opened more than one fragment at a time. Fragments are a more dynamic solution and they are the standard for newer Android versions.

PopupWindow 更简单,对用户提出的简单问题非常有帮助.

PopupWindow is simpler and it is very helpful on simple questions to the user.

推荐答案

支持库可以给你一个DialogFragment,它兼容旧版本的android.继续使用片段对话框,因为您要问的是非常具体的(3 个微调器和一个编辑文本.只需右键单击您的项目,然后按Android 工具"->添加支持库"确保在使用对话框导入时

The support library can give you a DialogFragment which is compatible with old versions of android. Go ahead with the fragment dialog cuz what you're asking is pretty specifical (3 spinners and an edittext. Just right click your project and press on "Android tools" --> "Add support library" Make sure when you use the dialog to import

import android.support.v4.app.DialogFragment;

否则你最终会在没有支持的情况下使用对话框:P.您将更灵活地使用对话框片段,并且可以毫不费力地使用您认为合适的视图(甚至是您自己制作的布局).

Else you'll end up using the dialog without the support :P. You will have more flexibility with the dialog fragment and the power to use the view you see fit (even a layout made by yourself) without much effort.

对话框片段

优点:

  • 能够添加任何视图
  • 易于编辑
  • 只需修改布局即可适应平板电脑或手机横屏或竖屏
  • 可以专门开设一个全新的课程来按照您的方式进行修改

缺点:

  • 视图越复杂,占用的内存越多
  • 更难编码

弹出窗口:

优点:

  • 更简单
  • 更容易编码
  • 它更标准,因此用户更难混淆

缺点:

  • 更简单,这意味着对它的控制更少
  • 仅限于几个模板

这些只是我的想法和我的经验,但你应该阅读文档

These are just from the top of my mind and from my experience, but you should read the documentation

http://developer.android.com/reference/android/widget/弹出窗口.html

http://developer.android.com/reference/android/app/DialogFragment.html

这篇关于我应该使用 PopupWindow 还是 DialogFragment 来接受输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆