什么是“最佳实践”?用于从“活动”更改为“活动”到“碎片”对于 Android 应用程序?

发布于 2024-11-09 13:10:50 字数 180 浏览 0 评论 0原文

我正在为Android平台编写一个应用程序。该应用程序已经几乎为 2.x 版本编写,但我也想为 Honeycomb 版本编写它。如您所知,Honeycomb 对于选项卡目标有“片段”而不是“活动”。

我的应用程序中有大约30个活动,必须将其更改为片段。这对我来说可能很难,所以我想知道这样做的“最佳实践”。

谢谢。

I am writing an application for Android platform. The application is already almost written for 2.x version, but I want to make it also for Honeycomb version. As you know, Honeycomb has 'Fragments' rather than 'Activities' for tab target.

There is about 30 activities in my application and it must be changed to fragments. It could be very hard word for me, so I want to know the 'best practice' about doing it.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨敛清荷 2024-11-16 13:10:50

并不是真正的 100% 答案,而只是我到目前为止的个人经验(如果我有什么问题,请纠正我,任何人 - 我仍然是 Android 的初学者):

我有同样的情况 atm,并认为我可以重新- 使用我的活动并更改布局。例如,我打算在左侧显示我的主菜单,在右侧显示所有其他活动。

然而,我很快意识到这在平板电脑上并不适用。它看起来很糟糕,甚至没有意义,因为如果使用得当,操作栏几乎取代了我的主菜单。此外,增加的空间确实需要完全不同的布局。在我的应用程序中,这将完全改变用户体验,因此我必须重新考虑整个应用程序。

另一方面,我必须一次又一次重复的东西现在可能会被没有 UI 的“隐形”片段所取代。我还没有仔细研究过 Honeycomb API 的这一部分,但它听起来至少很有希望。

我发现一个很好的功能是您现在可以非常轻松地“关闭”您的应用程序。就我而言,我只有一个 Activity,因此简单的“完成”即可优雅地退出整个应用程序。我知道这不是处理应用程序生命周期的“Android 方式”。然而,虽然我不会错过 Android 手机上的“关闭”按钮(尽管某些应用程序,尤其是游戏,提供了一个),但我发现自己一次又一次地在 Honeycomb 上寻找一个。 (这可能是因为 GUI 让人想起桌面应用程序之一。)

无论如何,长话短说:我建议重新考虑您的平板电脑应用程序。那里确实有空间,所以如果你不正确使用它,它看起来就会很奇怪。我不知道这对您的应用程序意味着什么 - 这显然取决于它是什么类型的应用程序。有些活动您可能只能用作片段,有些会与其他活动合并,有些可能变得可有可无。

所以我想你应该首先决定你的应用程序是否真的在平板电脑上有意义。如果没有,您可以执行一些“优化”小技巧(例如应用全息主题,也许还有新的布局/资源)。对于其他一切,我会等待 4.0/冰淇淋三明治,因为那时您将能够在智能手机和平板电脑上使用 Fragments。

Not really an 100% answer, but just my personal experience so far (and please correct me, anybody, if I got something wrong - I'm still a beginner to Android):

I have the same situation atm and thought I could just re-use my activities and change the layout. E.g. I intended to show my main menu on the left side and all other activities on the right.

However, I soon realized that this isn't really working on Tablet. It just looked crappy and didn't even make sense as the Action bar pretty much replaced my main menu, if used properly. Also, the increased space really screams for a completely different layout. In my app, this will change the user experience completely, so I'll have to re-think the whole app.

On the other hand, stuff that I had to repeat again and again might now be replaced by "invisible" fragments with no UI. I haven't looked closer to this part of the Honeycomb API, but it sounds at least promising.

What I found a nice feature is that you now can "close" your app very easily. In my case I only have one Activity, so a simple "finish" gracefully quits the whole app. I know that this isn't the "Android way" to deal with app life cycle. However, while I don't miss the "close" button on my Android phone (even though some apps, especially games, offer one) I catch myself again and again looking for one on Honeycomb. (That's probably because the GUI reminds one of desktop applications.)

Anyway, long story short: I would recommend re-thinking you app for Tablet. You really have SPACE there, so it just looks strange if you don't use it properly. What this means for your app I don't know - it obviously depends on what kind of app it is. Some activities you'll probably can just use as fragments, some will merge with others, some might become dispensable.

So I guess you should decide first of all if your app really makes sense on Tablets. If not, you could just do the little "optimze" tricks (like applying the holografic theme and maybe new layouts/resources). For everything else I would wait for 4.0/Ice Cream Sandwich, as you will be able to use Fragments on both Smartphone and Tablet then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文