Android 最佳实践 - 视图/活动
刚刚开始android开发。首先,我正在构建一个应用程序,其功能类似于画廊+图像查看器,并具有快速将图片移动到子文件夹中的附加功能,以便轻松对大量图片进行排序。
到目前为止,我有 2 个活动 - 全屏图像视图和全屏缩略图网格(用于多选目的)。
现在,由于我是新手,我想知道这种双重活动是否是一个明智的决定。简单地在内容视图之间切换比从图像视图切换到网格视图时启动完全不同的活动更好(反之亦然)。
我所寻找的当然是明显的优点和缺点——性能、易用性和可用性。但如果其中之一存在更基本的“模式”/最佳实践原因。
谢谢
Just starting out on android developing. To start off, I'm building an app which is gonna function like a gallery+image viewer, with the added functionality of quickly and swiftly moving pictures into subfolders, for easy sorting of lots of pictures.
So far I have 2 activites - a full screen image view, and a full screen thumbnail grid (for multiselect purposes).
Now as I'm new at this, I was wondering if this dual-activity was a wise decision. Would it be better to simply switch between content views than to power up an entirely different activity when switching from image view to grid view (and vice versa).
What I'm looking for are of course the obvious pros and cons - performance, ease and usability. But also if there are more fundamental "pattern"/best practice reasons for one or the other.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的双重活动方法是明智的。一般来说,Android 活动/视图 API 的结构是围绕每个活动有一个固定的视图。尽管您可以在 Activity 的布局中操作视图,但我建议这应该仅限于隐藏/显示/移动视图,而不是批量替换布局。
您可能应该考虑的是较新的 Fragments API。这几乎可以被视为“活动中的活动”。片段本质上允许您将 UI 元素(布局和行为)包装在可重用组件中。因此,在您的具体示例中,两个不同的 UI 可能是单个活动中的片段。
这有几个好处,例如能够在其他活动中重用您的 UI,并且您可以制作时髦的过渡动画。
I think your dual activity approach is sensible. Generally speaking the Android Activity/View APIs are structured around having a single fixed View per Activity. Although you can manipulate Views within your Activity's layout, I'd suggest this should be restricted to hiding/showing/moving Views rather than replacing the layout wholesale.
What you probably should consider is the newer Fragments API. This can almost be though of as "activities within activities". A Fragment essentially allows you to wrap up an element of a UI (layout and behaviour) in a reusable component. So in your specific example, the two distinct UIs could be Fragments within a single activity.
This has a couple of benefits such as being able to reuse your UIs in other activities and you can do funky transition animations.
双重活动应该可以工作,因为您不会因执行后退按钮操作而烦恼。
dual activity should work, as you won't be bothered by implementing the back button action.
活动正是为了这个目的而开展的。如果您愿意,您可以使用自定义布局引擎(重新加载组件等)将整个应用程序放在一个活动中,如果您想要一个“便携式”应用程序(例如,您开发一个具有通用布局的应用程序),这就是您想要做的适用于各种平台(Andropid、Windows 7、iOS 等)的 UI,但如果您只想使用 Android,首选方法是使用提供的 API,而不是重新发明轮子。它运行良好,并且会给用户带来舒适的一致性体验(它的外观和感觉就像其他 Android 应用程序一样)。
我当前正在进行的项目(游戏)已经有 10 种不同的活动,并且我正在计划更多...
Activities were made exactly for this purpose. If you prefer, you can have your whole application in a single activity with a custom layout engine (reload components, etc.) and that's what you want to do if you want a "portable" app (e.g. you develop an app with a common UI for various platforms, Andropid, Windows 7, iOS, etc.), but if you want to go Android only, the preferred way is to use the provided APIs, and not to reinvent the wheel. It works fine, and will give users a comforting sense of consistency in their experience (it will look and feel like other Android apps).
The current project I'm working on (a game) already has 10 different activities, and I'm planning more...