I am currently playing around with one and two pane mode in Android, using Fragments. Basically I am having some kind of Master/Detail flow, where every Detail is again a Master for other Details.
For example we have a Master Clients with the Detail Client. Each Client is again some kind of Master with a list of Orders. The Orders then have the Detail Order. Each Order has a list of Articles with the Detail Article and so on.
So I would like to have a two pane layout, with the Master on the left and the Detail on the right. As every Detail is a Master to, when going to it's Details i would like to shift the whole Layout to the left. So the "old" Master falls out of the Layout on the left and the new List/Detail enters the Layout from the right.
It should basically look something like this:
On the left I have the Clients and on the right I have the detail of the selected client John.
Now if I click on the Orders... in the detail, I want to move in the Orders list from right, pushing the Clients master and the detail to the left.
The result should look something like this:
So basicly the Clients master moved out of the Layout, the Client detail is now on the left and the Orders master is on the right.
Clicking on one of the Orders should again, move the detail of that Order in from the right and push the Client master out on the left.
The result:
To create the transition I did the following:
- Create a horizontal
LinearLayoutwith 3FrameLayoutchildren. - Set the
layout_weightof the 1st and 2ndFrameLayoutto 1.0f and the one of the 3rd to 0.0f. - Create an
Animationfor thelayout_weightof the 1st and 3rdFrameLayout, turning the 1st from 1.0 to 0.0 and the 3rd from 0.0 to 1.0 - Wait until the
Animationfinishes - Replace the
Fragmentfrom the 1stFrameLayoutwith the one from the 2nd and move theFragmentfrom the 3rdFrameLayoutinto the 2nd. - Reset the
layout_weight.
This works perfectly, if you remember to remove the Fragment from one container before adding it to the other.
The problem I am having with this solution is, when i want to go back.
As a user I would expect, that the previous master comes in from the left and pushes the current detail out on the right (the reverse animation).
I guess it would be the best to use the Fragment-Backstack, but i just can't figure out how to do it.
So how should I manage the "going back"? Or is there a better solution for this kind of "multi-level master-detail flow"?


