从双窗格切换到单一界面上的方向变化保持片段堆栈 [英] Switch from dual pane to single pane on orientation change maintaining fragment stack

查看:192
本文介绍了从双窗格切换到单一界面上的方向变化保持片段堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有横向和纵向上的平板电脑的双面板布局。

Currently I have a dual pane layout for both landscape and portrait on a tablet.

类似地说设置我有它加载一个片段插入左侧选择窗格中的单一活动,然后选择在任何合适的片段正在显示结果进一步片段制成显示到右侧窗格中增加了backstack一路。

Similar to say settings I have a single activity which loads a fragment into the left selection pane and then choices made in whatever right fragment is being shown result in further fragments being displayed into the right pane adding to the backstack all the way.

现在我可以看到,对于一些药片这将是有意义的有肖像单窗格和双另一个用于景观。不过,我想以下行为:

Now I can see that for some tablets it would make sense to have a single pane for portrait and a dual one for landscape. However, I would want the following behaviour:

A)如果横向深度的片段堆栈的 N 说的是在右窗格中,然后在一个方向改变为纵向我仍然希望片段以显示ñ和被保持在堆栈

A) If in landscape a fragment stack of depth N say is in the right pane then on an orientation change to portrait I would still want fragment N to be displayed and the stack to be maintained

B)然后导航从片段后面的 N 在纵向模式下我最终还是要回来的选择屏幕。

B) Then navigating back from fragment N in portrait mode I eventually want to come back to the selection screen.

现在我无法弄清楚如何做到这一点,想法,我想出迄今有:

Now I can't figure out how to achieve this, ideas that I've come up with thus far are:

1)有双窗格为两个方向,但隐藏左边的一个方向上的变化,然后将需要重新出现。隐藏右边的窗格中时,堆栈被清除。

1) Have dual panes for both orientations but hide the left one on orientation change, would then need to reshow and hide right pane when stack is cleared

2)重建,将它们放入新containter,将在开始选择片段切换到肖像

2) Rebuild the stack into the new containter, adding the selection fragment at the beginning on a switch to portrait

都不是,如果他们的工作,似乎完全令人满意给我。只是想知道这样做的更好/推荐的方法是。

Neither, if they work, seem entirely satisfactory to me. Just wondering what the better/recommended way of doing this is.

在此先感谢。彼得。

修改1

值得一提的,我明白,你可以有不同的布局纵向和横向和我完成了一个大项目与纵向和横向上的方向变化的周期,以便确定一个双窗格布局。我也看了看 FragmentLayoutSupport 的例子,但不保持在一个方向变化portriat右侧窗格中的数据,它再次显示列表。

It should be mentioned that I understand that you can have have different layouts for portrait and landscape and am finishing up a large project with a dual pane layout for both portrait and landscape so OK on the lifecycle of an orientation change. I have also looked at the FragmentLayoutSupport example but that doesn't maintain the data in the right pane on an orientation change to portriat, it shows the list again.

推荐答案

PJL,所以你是在正确的轨道在这里,要么你可以检查你的方向,然后显示或隐藏特定的片段,也可以有两个不同的布局之一肖像,一个景观,在活动​​中您的onCreate功能,然后你可以检查第二个片段可通过findViewById,然后实例化与否。你正在寻找的视图只会有一个已知的ID的的FrameLayout。 因此,请确保您了解在一个方向变化这里 一个真正好的片段示例是图书的忙codeR指南,以先进的Andr​​oid开发这本书是40 $ /年描述的一部分。样品code是免费的,但。查看片段为例的它可能会帮助你的问题。当然也可以看看这个例子<一href="http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentLayoutSupport.html"相对=nofollow> FragmentLayoutSupport.java 上developer.android.com

PJL, so you are on the right track here, either you can check your orientation and then show or hide specific fragments or you can have two different layouts one for Portrait and one for Landscape, in your onCreate function of your Activity you can then check if the second Fragment is available via findViewById and then instantiate it or not. The View you are looking for would just have a FrameLayout with a known Id. So make sure you understand what happens during an orientation change enter link description here A really good Fragments Example is part of the Samples of the Book The Busy Coder's Guide To Advanced Android Development the book is part of a 40$ / year description. The Sample code is free though. Check out the Fragments Example it might help with your problems. Also of course you can have a look at the example FragmentLayoutSupport.java on developer.android.com

这篇关于从双窗格切换到单一界面上的方向变化保持片段堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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