模式何时使用活性转换VS动态片段 [英] Patterns when to use Activity Transition vs Dynamic Fragments

查看:90
本文介绍了模式何时使用活性转换VS动态片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有如何处理用户界面转换中的Andr​​oid活动与片段的任何模式?我目前正进一步调查中最多有3列在景观的UI。 我想UI以开始与一路在屏幕,然后在选择的一些移动在第二列,然后点击东西在第二淡入上片剂和电话的第三1列和淡出第一柱在手机上。 我想知道我应该这样做作为一个活动的过渡,当我应该只使用片段,出现意见。据我已阅读片段可以移动到其他活动,所以我的选择是要么实现与静态列布局,然后过渡采取的片段,它们或者有一个活动的所有3列,并有活动的管理亮相活动片段。这两种方法都可以工作,但我感兴趣的是从尽可能多的角度对两种方案的利弊。

Are there any patterns on how to handle UI Transitions in Android Activities vs Fragments? I am currently looking into a UI that has at most 3 columns in Landscape. I would like the UI to start with 1 column all the way across the screen and then on selection of something move in the second column and then on clicking on something in the second fade in the 3rd on tablets and phones and fade out the 1st column on phones. I am wondering when I should do this as an Activity transition and when I should just use Fragments with Views that Appear. As far as I have read fragments can be moved over to other activities so my choice is either implement Activities with static column layouts that then transition taking the fragments with them or have one Activity with all 3 columns and have the Activity manage the Appearing of the Fragments. Both approaches could work but I was interested in pros and cons from as many angles for both solutions.

有两个问题相似,我要问,但不太回答我

There are two questions similar to what I am asking but don't quite answer mine

  • <一个href="http://stackoverflow.com/questions/5328606/two-panel-ui-with-fragments-vs-separate-activities">Two面板UI与片段VS独立活动
  • <一个href="http://stackoverflow.com/questions/6373631/android-honeycomb-layout-problem-hide-show-framelayouts">Android蜂窝:布局问题 - 隐藏/显示FrameLayouts
  • Two panel UI with Fragments vs Separate activities
  • Android Honeycomb: layout problem - hide/show FrameLayouts

推荐答案

片段似乎是更多code前面(因为你把一个视图中的片段,并在活动片段,而不是只在活动视图),但他们是伟大的节省您的头痛,在短短这种情势与片段一定要去。他们甚至处理过渡给你。

Fragments can seem like more code up front (since you're putting a view in a fragment, and a fragment in an Activity, instead of just a view in an Activity), but they're great at saving you from headaches in just this kind of situation- Definitely go with Fragments. They even handle the transitions for you.

我们有一些样品code称为蜂巢画廊你可以看看这里< /一>,它具有一个两列加动作条布局,并显示/隐藏最左列的能力。这应该给你搞清楚怎么办布局多个片段,并显示/隐藏他们一个良好的开端。

We have some sample code called "Honeycomb Gallery" you can take a look at here, which has a two-column-plus-actionbar layout, and the ability to show/hide the leftmost column. This should give you a good head start in figuring out how to do layout for multiple fragments and show/hide them.

仅供参考,其中一个重要的权衡使用多个片段的活动,而不是多个活动,是片段不直接回应意图 - 举例来说,如果你有一个笔记应用程序,其中的查看说明页面是一个活动,你改变它,以便有一个查看记片段的主要活动里面,那么你就必须将其设置使得主要活动收到一张纸条ID和注操作(创建,查看,编辑,等等)的意图,而不是仅仅具有查看记录活动收到的说明ID的意图。随后,主要活动将需要建立片段在页面上相应。不是一个大问题,但如果通过意向的外部访问到应用程序的各个部分是很重要的,那么它可能会更容易打破你的应用程序外面的一些活动,以及利用碎片重新present的各个组件。

FYI, one important trade-off to using multiple fragments in an Activity instead of multiple Activities, is that fragments don't directly respond to intents - For instance, if you had a note-taking app where "View Note" page was an Activity, and you changed it so that there was a "view note" Fragment inside the main Activity, then you'd have to set it up such that the main Activity received a note ID AND a note action (create, view, edit, whatever) in the Intent, as opposed to just having the "view note" activity receive the note ID in the Intent. The main Activity would then need to set up the fragments on the page accordingly. Not a huge deal, but if external accessibility to various parts of your application via Intent is important, then it might be easier to break your app out into a few Activities, as well as use fragments to represent the individual components.

这篇关于模式何时使用活性转换VS动态片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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