如何写有非常深的导航一个Android的多窗格应用程序 [英] How to write an Android multi-pane app with very deep navigation

查看:151
本文介绍了如何写有非常深的导航一个Android的多窗格应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR: 应该如何多面板的应用程序深的导航类似于Spotify的iPad应用程序的外观和工作在Android,以及如何实现这一点?

TL;DR: How should multi-pane apps with deep navigation similar to the Spotify iPad app look and work on Android, and how to implement this?

龙版本: 我工作的一个应用程序,用户看到的项目列表,然后可以深入研究这些项目。这些项目的详细信息页面可以对相关项目再次开放名单,这反过来有详细页等。作为一个手机应用程序,这将是独立的活动可能看起来和彼此联系起来是这样的:

Long version: I'm working on an app, where the user sees lists of items and can then delve deeper into these items. These item detail pages can again open lists of related items, that in turn have detail pages and so on. As a phone app, these would be separate Activities that might look and link to each other like this:

在实物模型,用户将看到一个初步的了解,然后从第一个列表中选择项目#2。一项新的活动打开了,显示他的详细信息项目#2。在这里,他选择看就项目#2事情的清单。在第三张新双头呆活动显示了这个列表,点击在一个打开的细节这件事。他能深导航到内容,因为他喜欢。

In the mock-ups, the user sees an initial overview and then selects "Item #2" from the first list. A new Activity opens up, showing him details for Item #2. Here, he selects to see a list of Things relating to Item #2. The newly openend Activity in the third picture shows this list, and clicking on one opens the details for this thing. He can navigate as deep into the content as he likes.

这工作得很好,平时的Andr​​oid活动。我正在使应用程序,以平板电脑和正在思考如何最好地实现这一点。该计划是创建具有相同概念的多面板布局。这是非常类似于如何在iPad的Spotify应用程序的工作原理(这将是有趣的,看看他们是如何把这个到Android,一旦他们创造平板电脑的具体布局)。

This works quite well with the usual Android Activities. I'm working on bringing the app to tablets and am thinking on how to best implement this. The plan is to create a multi-pane layout with the same concept. It is very similar to how the iPad Spotify app works (it will be interesting to see how they bring this to Android once they create tablet-specific layouts).

在平板电脑的布局,每点击一个项目或列表的名称可打开相应的子项作为从右侧动画在一个新的面板。同样的工作流程在上面的例子是这样的:

In the tablet layout, each click on an item or list name opens the corresponding child item as a new pane that animates in from the right. The same workflow as in the example above would look like this:

我不能确定如何最好地实现这种导航模式。具有有限的导航深度一样的GMail复合窗格应用程序可以使用静态的ViewGroup建(的LinearLayout将是确定)包含所有的片段,并深入到导航替换的下一个容器的内容物的权利和动画向此(见在SO CommonWares执行本)。

I'm unsure how to best implement this navigation pattern. Multi-pane apps with a limited navigational depth like GMail can be built with a static ViewGroup (LinearLayout would be ok) containing all fragments, and going deeper into the navigation replaces the content of the next container to the right and animates to this (see CommonWares implementation of this on SO).

这表明,一个自定义的ViewGroup将是一段路要走。如果它来显示子页面(即物清单),然后创建一个新的孩子在的ViewGroup是一半宽的片段画面,然后滚动可视区域,使这只是互动与窗格和新子是可见的。要正确链接此一FragmentTransaction,使背部栈正常工作,我想这将是这样的:

This suggests that a custom ViewGroup would be the way to go. If it has to display a subpage (i.e. "List of Things"), then it creates a new child in the ViewGroup that is half as wide the screen with the fragment and then scrolls the visible area so that the pane that was just interacted with and the new child are visible. To link this correctly to a FragmentTransaction, so that the back stack works correctly, I'd guess it would be something like this:

View newPane = container.addChild();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(newPane, new ListOfThingsFragment(2));
ft.remove(paneOnRight, fragmentOnRight);
ft.commit();
container.animateToRight();

我不明白的方式向FragmentTransaction内做动画。

I don't see a way to do the animation within the FragmentTransaction.

反馈的欢迎。我的雇主普遍良好就打开我们开发采购的框架,因此,如果这是这是更广泛的兴趣,如果我能想出​​了一个可重复使用的解决方案,我会很高兴分享。

Feedback welcome. My employer is generally favorable with respect to open sourcing frameworks we develop, so if this is something that is of broader interest and if I can come up with a reusable solution, I'd be glad to share it.

推荐答案

我们遇到了同样的问题与我们的应用程序。的限制,我们给自己:

We ran into the same problem with our app. The constraints we gave ourselves:

  • 在面板的动态数
  • 在每个窗格可以是不同尺寸
  • 在面板内部片段必须正确地保留在方向改变。

鉴于这些制约因素,我们建立了一个新的布局,我们称之为PanesLayout。您可以点击此处查看:

In light of those constraints, we built a new layout we call PanesLayout. You can check it out here:

https://github.com/cricklet/Android-PanesLayout

基本上,它可以让你轻松地添加任何数量的动态调整窗格和附加片段的窗格。希望你觉得它有用! :)

It basically allows you to easily add any number of dynamically sized panes and attach fragments to those panes. Hope you find it useful! :)

这篇关于如何写有非常深的导航一个Android的多窗格应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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